Mathematica 求值控制和表达式
我正在使用的表达式太复杂,无法在此处完全输入,但我提供了一个简单的示例来突出显示我遇到的问题。我希望有人有足够的编程毅力来帮助我解决这个问题。首先我要说的是,我总体上几乎没有编程背景,但我了解 Mathematica 的基础知识。非常感谢任何和所有的帮助。假设我已经设置了以下函数:
X[x_] := x Log[x]
X[0] := 0
Y[y_] := y Log[y]
Y[0] := 0
Z[z_] := z Log[z]
A[x_, y_, z_] := X[x] + Y[y] + Z[z]
In[7]:= A[x, y, z]
Out[7]= x Log[x] + y Log[y] + z Log[z]
In[8]:= B[x_, y_, z_] :=
Evaluate[A[x, y, z] - x*D[A[x, y, z], x] - y*D[A[x, y, z], y] -
z*D[A[x, y, z], z]]
In[9]:= B[x, y, z]
Out[9]= x Log[x] - x (1 + Log[x]) + y Log[y] - y (1 + Log[y]) +
z Log[z] - z (1 + Log[z])
我已经使用 X[x]
、Y[y] 的规则设置了
和 A[x,y,z]
]Z[z]
以便它可以处理 x,y,z == 0
的情况,即当 x == 0
我想要所有表达式A[x,y,z]
与 x
变为零或被忽略,包括 Log[x]
。我定义了一个函数 B[x,y,z]
,它涉及 A[x,y,z]
的偏导数。现在,我想要结果,以便 B[0,y,z]
产生
yLog[y]-y(1+Log[y])+zLog[z]-z(1+Log[z])
基本上返回并使得 A[x,y,z]:= Y[y]+ Z[z]
但我目前遇到了以下可以理解的错误:
Infinity::indet:遇到不确定表达式 0 (-[Infinity])。 >>
Mathematica 一定有某种方法可以解决这个问题,我想知道它是否会涉及 Hold 功能或相关的功能。谢谢大家的帮助。
The expressions I am working with are much too complicated to fully enter here, but I've included a simple examples that highlights the problem I am running into. I am hoping there is someone out there with enough programming fortitude to help me around this issue. Let me preface this by saying I have little to no background in programming in general, but I know the basics of Mathematica. Any and all help is greatly appreciated. Suppose I have set up the following functions:
X[x_] := x Log[x]
X[0] := 0
Y[y_] := y Log[y]
Y[0] := 0
Z[z_] := z Log[z]
A[x_, y_, z_] := X[x] + Y[y] + Z[z]
In[7]:= A[x, y, z]
Out[7]= x Log[x] + y Log[y] + z Log[z]
In[8]:= B[x_, y_, z_] :=
Evaluate[A[x, y, z] - x*D[A[x, y, z], x] - y*D[A[x, y, z], y] -
z*D[A[x, y, z], z]]
In[9]:= B[x, y, z]
Out[9]= x Log[x] - x (1 + Log[x]) + y Log[y] - y (1 + Log[y]) +
z Log[z] - z (1 + Log[z])
I have set up A[x,y,z]
with the rules for X[x]
, Y[y]
, and Z[z]
so that it can handle the case where x,y,z == 0
, i.e. when x == 0
I want all expressions in A[x,y,z]
with x
to go to zero or be neglected including Log[x]
. I've defined a function B[x,y,z]
that involves the partial derivatives of A[x,y,z]
. Now, I want the result so that B[0,y,z]
yields
yLog[y]-y(1+Log[y])+zLog[z]-z(1+Log[z])
that is to basically go back and make A[x,y,z]:= Y[y]+Z[z]
but instead I am currently running into the following, understandable, error:
Infinity::indet: Indeterminate expression 0 (-[Infinity]) encountered. >>
There must be some way around this with Mathematica and I am wondering if it will involve the Hold function or something related. Thank you all for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是在导数中使用虚拟变量,然后用实际值替换。
这是可行的,因为每个导数的因子都是 0。更通用的解决方案可能涉及在
X, Y, Z
上定义UpValues
来处理原点的导数(我不这样做)现在有时间检查一下)。One way is to use dummy variables in the derivatives, and replace afterward with the actual values.
This works because each derivative has a factor of 0. A more general solution might involve defining
UpValues
onX, Y, Z
for handling derivatives at the origin (I don't have time to check this at the moment).