Mathematica 使用返回函数

发布于 2024-12-02 00:44:29 字数 257 浏览 4 评论 0原文

我确信这非常简单,但我向 Mathematica 询问方程的特征多项式,如下所示:

m={
 {0, n, 0, c1},
 {R, 0, 4, c2},
 {0, R, 0, 0},
 {0, 0, R, c4}
}
CharacteristicPolynomial[m,x]

现在,我想将返回的多项式保存为函数,以便稍后可以调用它(大概使用类似 <代码>f[1])。唉,我一直不知道如何做到这一点。

I'm sure this is very simple, but I ask Mathematica for the characteristic polynomial of an equation, as follows:

m={
 {0, n, 0, c1},
 {R, 0, 4, c2},
 {0, R, 0, 0},
 {0, 0, R, c4}
}
CharacteristicPolynomial[m,x]

Now, I would like to save the returned polynomial as a function, so I can later call it (presumably with something like f[1]). Alas, I've been unable to figure out how to do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

还不是爱你 2024-12-09 00:44:29

这相当简单。只需执行此

f[x_] = CharacteristicPolynomial[m,x]

操作即可注意 Set (< code>=) 不是 SetDelayed (:=) 强制对 CharacteristicPolynomial 求值一次。如果您使用 SetDelayed,那么每次计算 f 时都会对其进行计算。

This is fairly straightforward. Simply do this

f[x_] = CharacteristicPolynomial[m,x]

Note the use of Set (=) not SetDelayed (:=) which forces CharacteristicPolynomial to be evaluated once. If you used SetDelayed, then it would be evaluated every time f is evaluated.

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