如何在函数定义中使用 Maxima 的 diff?

发布于 2024-12-21 04:47:36 字数 278 浏览 5 评论 0原文

我想在另一个函数中使用一个函数的导数。在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

提笔书几行 2024-12-28 04:47:36

请注意,只有在解析代码时才能理解引用引用。如果您只在解释器中工作,那没关系,但如果您将内容放入脚本中,则可能会产生意想不到的效果。

另一种方法可以做到这一点。它在解释器和脚本中的工作方式相同。

define (g(x), diff (f(x), x) - 8);

参见“定义”。

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.

define (g(x), diff (f(x), x) - 8);

See 'define'.

爱你是孤单的心事 2024-12-28 04:47:36

Michael 的答案很好,但每次调用 g(x) 时都会进行微分。 (此外,通常您会看到它包装在 block 语句中,以确保 y 正确本地化)。

有一种方法可以强制 RHS 在定义时进行评估
以及一般的x
语法是

(%i1) f(x) := 2*x^4;
                                            4
(%o1)                            f(x) := 2 x
(%i2) g(x) := ''(diff(f(x), x) - 8);
                                          3
(%o2)                          g(x) := 8 x  - 8
(%i3) g(0);
(%o3)                                 - 8

与块结构比较:

(%i4) h(x) := block([y], subst([y = x], diff(f(y), y) - 8));
(%o4)        h(x) := block([y], subst([y = x], diff(f(y), y) - 8))
(%i5) h(0);
(%o5)                                 - 8

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 a block statement to ensure that y 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

(%i1) f(x) := 2*x^4;
                                            4
(%o1)                            f(x) := 2 x
(%i2) g(x) := ''(diff(f(x), x) - 8);
                                          3
(%o2)                          g(x) := 8 x  - 8
(%i3) g(0);
(%o3)                                 - 8

Compare with the block construct:

(%i4) h(x) := block([y], subst([y = x], diff(f(y), y) - 8));
(%o4)        h(x) := block([y], subst([y = x], diff(f(y), y) - 8))
(%i5) h(0);
(%o5)                                 - 8

Notice (%o4) which shows that the RHS is unevaluated.

Ref: http://www.math.utexas.edu/pipermail/maxima/2007/004706.html

尛丟丟 2024-12-28 04:47:36

不确定这是否是最简单的答案,但它似乎对我来说是正确的事情

(%i) g(x) := subst([y = x], diff(f(y), y) - 8);

(%i) g(x);
         8 x^3 - 8
(%i) g(0);
         -8
(%i) g(1);
         0

Not sure if this is the simplest answer, but it seems to do the right thing for me

(%i) g(x) := subst([y = x], diff(f(y), y) - 8);

(%i) g(x);
         8 x^3 - 8
(%i) g(0);
         -8
(%i) g(1);
         0
孤者何惧 2024-12-28 04:47:36

g(X) := at(diff(f(x),x)-8,x=X);

g(X) := at(diff(f(x),x)-8,x=X);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文