如何在函数定义中使用 Maxima 的 diff?
我想在另一个函数中使用一个函数的导数。在 Maxima 中应该如何完成此操作?
例如:
f(x) := 2*x^4;
g(x) := diff(f(x),x)-8;
现在 g(x)
按预期产生 8x^3-8
,但是 g(0)
给出错误,因为 diff(f(0),0)
没有意义。但是我应该如何正确定义g?
I want to use a function's derivative in an other function. How should this be done in Maxima?
E.g:
f(x) := 2*x^4;
g(x) := diff(f(x),x)-8;
Now g(x)
yields 8x^3-8
as expected, but g(0)
gives an error, since diff(f(0),0)
doesn't make sense. But then how should I properly define g?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请注意,只有在解析代码时才能理解引用引用。如果您只在解释器中工作,那没关系,但如果您将内容放入脚本中,则可能会产生意想不到的效果。
另一种方法可以做到这一点。它在解释器和脚本中的工作方式相同。
参见“定义”。
Note that quote-quote is only understood when the code is parsed. That's OK if you only work in the interpreter but if you put stuff into scripts, it is possible to have unintended effects.
Another way to do this. It works the same in the interpreter and in a script.
See 'define'.
Michael 的答案很好,但每次调用 g(x) 时都会进行微分。 (此外,通常您会看到它包装在
block
语句中,以确保y
正确本地化)。有一种方法可以强制 RHS 在定义时进行评估
以及一般的
x
。语法是
与块结构比较:
Notice (%o4),它表明 RHS 未被评估。
参考:http://www.math.utexas.edu/pipermail/maxima/2007/004706。 html
Michael's answer is good, but it does the differentiation everytime
g(x)
is called. (Also, normally you see it wrapped in ablock
statement to ensure thaty
is properly localized).There is a way to force the RHS to evaluate at the time of definition
and with the general
x
.The syntax is
Compare with the block construct:
Notice (%o4) which shows that the RHS is unevaluated.
Ref: http://www.math.utexas.edu/pipermail/maxima/2007/004706.html
不确定这是否是最简单的答案,但它似乎对我来说是正确的事情
Not sure if this is the simplest answer, but it seems to do the right thing for me
g(X) := at(diff(f(x),x)-8,x=X);
g(X) := at(diff(f(x),x)-8,x=X);