How do I use lhs and rhs to define a function?

烂漫一生 提交于 2019-12-11 12:04:14

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/18343054/how-do-i-use-lhs-and-rhs-to-define-a-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!