如何在mathematica中进行函数替换
我有表达式 D[f[x, y], x]
,我想用 x*y
替换 f[x,y]
code>,我尝试了以下操作:
D[f[x, y], x] /。 {f[x,y]-> x*y}
和 D[f[x, y], x] /。 {f->; x*y}
但两者都不起作用。将不胜感激您的帮助!谢谢。
I have the expression D[f[x, y], x]
, and I want to substitute f[x,y]
with x*y
, I tried the following:
D[f[x, y], x] /. {f[x,y] -> x*y}
andD[f[x, y], x] /. {f -> x*y}
But neither worked. Would appreciate your help! Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
表达式中导数的
FullForm
是这应该解释为什么第一个规则失败 - 表达式中不再有
f[x,y]
。第二条规则失败,因为Derivative
认为f
是一个函数,而您用表达式替换它。您可以做的是:请注意,纯函数周围的括号是必不可少的,以避免与优先级相关的错误。
或者,您可以通过模式定义您的 rhs:
HTH
The
FullForm
of the derivative in your expression isThis should explain why the first rule failed - there is no
f[x,y]
in your expression any more. The second rule failed becauseDerivative
considersf
to be a function, while you substitute it by an expression. What you can do is:Note that the parentheses around a pure function are essential, to avoid precedence - related bugs.
Alternatively, you could define your r.h.s through patterns:
HTH
没什么新鲜的,只是我通常的想法:
Out
Nothing new, just the way I usually think of it:
Out
您还可以尝试“保留并释放”或“推迟”等。
You can also try Hold and Release or Defer etc.