In the Maxima session below, how come f(1) is not 0?

(%i1) eq: 2 * x + 1 = 3;
(%o1)                             2 x + 1 = 3
(%i2) f(x) := lhs(eq) - rhs(eq);
(%o2)                      f(x) := lhs(eq) - rhs(eq)
(%i3) f(1);
(%o3)                               2 x - 2
有帮助吗?

解决方案

the process of function calling in maxima here binds x to 1 in the function definition, lhs(eq)-rhs(eq). That has no x in it, so that binding does nothing. Next, lhs(eq) is evaluated to 2*x+1. rhs(eq) is evaluated to 3. etc.

Do you always want the same equation eq? perhaps you want to do

define(f(x),lhs(eq)-rhs(eq));

to check what the definition is, try grind(f);

If you want to vary the equation maybe something like

g(val, eq) := subst(val,x, lhs(eq)-rhs(eq)) ; would do.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top