Mathematica 求值控制和表达式

发布于 2024-12-25 05:39:54 字数 1205 浏览 1 评论 0原文

我正在使用的表达式太复杂,无法在此处完全输入,但我提供了一个简单的示例来突出显示我遇到的问题。我希望有人有足够的编程毅力来帮助我解决这个问题。首先我要说的是,我总体上几乎没有编程背景,但我了解 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 技术交流群。

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

发布评论

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

评论(1

没有心的人 2025-01-01 05:39:54

一种方法是在导数中使用虚拟变量,然后用实际值替换。

Clear[X, Y, Z];
X[x_] := x Log[x]
X[0]   = 0;
Y[y_] := y Log[y]
Y[0]   = 0;
Z[z_] := z Log[z]
Z[0]   = 0;

A[x_, y_, z_] := X[x] + Y[y] + Z[z]    
B[x_, y_, z_] := 
 Module[{xx, yy, zz}, 
  A[x, y, z] - x*D[A[xx, y, z], xx] - y*D[A[x, yy, z], yy] - 
    z*D[A[x, y, zz], zz] /. {xx -> x, yy -> y, zz -> z}]

B[0, y, z]

(* Output: y Log[y] - y (1 + Log[y]) + z Log[z] - z (1 + Log[z]) *)

这是可行的,因为每个导数的因子都是 0。更通用的解决方案可能涉及在 X, Y, Z 上定义 UpValues 来处理原点的导数(我不这样做)现在有时间检查一下)。

One way is to use dummy variables in the derivatives, and replace afterward with the actual values.

Clear[X, Y, Z];
X[x_] := x Log[x]
X[0]   = 0;
Y[y_] := y Log[y]
Y[0]   = 0;
Z[z_] := z Log[z]
Z[0]   = 0;

A[x_, y_, z_] := X[x] + Y[y] + Z[z]    
B[x_, y_, z_] := 
 Module[{xx, yy, zz}, 
  A[x, y, z] - x*D[A[xx, y, z], xx] - y*D[A[x, yy, z], yy] - 
    z*D[A[x, y, zz], zz] /. {xx -> x, yy -> y, zz -> z}]

B[0, y, z]

(* Output: y Log[y] - y (1 + Log[y]) + z Log[z] - z (1 + Log[z]) *)

This works because each derivative has a factor of 0. A more general solution might involve defining UpValues on X, Y, Z for handling derivatives at the origin (I don't have time to check this at the moment).

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