如何在mathematica中扩展微分运算符的算术 [英] How to expand the arithmetics of differential operators in mathematica

查看:32
本文介绍了如何在mathematica中扩展微分运算符的算术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比如我想让mma展开下面的微分算子

For example, I want mma to expand out the following differential operator

(1+d/dx+x*d2/dy2)^2*(1+y*d/dy)^2

我发现 Nest 不足以做这种事情.

I found Nest is not good enough to do this sort of things.

推荐答案

有点过时,但请参阅

http://library.wolfram.com/infocenter/Conferences/325/

一些非交换代数运算"部分提供了一些方法来解决这个问题.第一个示例定义了一个名为 differenceOperate 的函数,可能最适合您的目的.

The section "Some noncommutative algebraic manipulation" gives a few ways to go about this. The first example, defining a function called differentialOperate, is probably best suited for your purposes.

---编辑,重新编辑---

---edit, reedited---

这是我使用的代码.可能它(仍然)缺少一些改进.它取自上述笔记本中的几个示例.

Here is the code I use. Probably it is (still) missing a few refinements. It is taken from a couple of examples in the notebook mentioned above.

我将定义并使用一个辅助谓词 scalarQ.这为将显式数值以外的实体声明为标量提供了灵活性.

I will define and use an auxiliary predicate, scalarQ. This gives the flexibility of declaring entities other than explicit numerical values to be scalar.

我定义了一个非交换乘法,称为 ncTimes.理想情况下,我将只使用 NonCommutativeMultiply,但我无法让模式匹配按照我想要的方式运行零或一个参数形式,或者拉出标量.(技术含量较低的解释:它的魔力比我的更强大.)

I define a noncommutative multiplication, called ncTimes. Ideally I would just use NonCommutativeMultiply, but Iwas not able to get the pattern matching to behave the way I wanted with respect to zero or one argument forms, or pulling out scalars. (Less technical explanation: it's mojo was more powerful than mine.)

scalarQ[a_?NumericQ] := 真scalarQ[_] := False

scalarQ[a_?NumericQ] := True scalarQ[_] := False

ncTimes[] := 1ncTimes[a_] := ancTimes[a_, ncTimes[b_, c], d_] := ncTimes[a, b, c, d]ncTimes[a_, x_ + y_, b_] := ncTimes[a, x, b] + ncTimes[a, y, b]ncTimes[a_, i_?scalarQ*c_, b_] := i*ncTimes[a, c, b]ncTimes[a_, i_?scalarQ, b___] := i*ncTimes[a, b]

ncTimes[] := 1 ncTimes[a_] := a ncTimes[a_, ncTimes[b_, c], d_] := ncTimes[a, b, c, d] ncTimes[a_, x_ + y_, b_] := ncTimes[a, x, b] + ncTimes[a, y, b] ncTimes[a_, i_?scalarQ*c_, b_] := i*ncTimes[a, c, b] ncTimes[a_, i_?scalarQ, b___] := i*ncTimes[a, b]

differentialOperate[a_, expr_]/;FreeQ[a, D] := a*expr差分操作[L1_ + L2_, expr_] :=微分操作[L1,expr] +微分操作[L2,expr]差分操作[a_*L_, expr_]/;FreeQ[a, D] :=a*differentialOperate[L, expr]DifferentOperate[a : HoldPattern[D[] &], expr_] := a[expr]差分操作[ncTimes[L1, L2_], expr_] :=展开[微分操作[L1,微分操作[L2,expr]]]差分操作[L1_^n_Integer, expr_]/;n > 1 :=Nest[Expand[differentialOperate[L1, #]] &, expr, n]

differentialOperate[a_, expr_] /; FreeQ[a, D] := a*expr differentialOperate[L1_ + L2_, expr_] := differentialOperate[L1, expr] + differentialOperate[L2, expr] differentialOperate[a_*L_, expr_] /; FreeQ[a, D] := a*differentialOperate[L, expr] differentialOperate[a : HoldPattern[D[] &], expr_] := a[expr] differentialOperate[ncTimes[L1, L2_], expr_] := Expand[differentialOperate[L1, differentialOperate[L2, expr]]] differentialOperate[L1_^n_Integer, expr_] /; n > 1 := Nest[Expand[differentialOperate[L1, #]] &, expr, n]

In[15]:= ddvar[x_, n_: 1] := D[#, {x, n}] &

In[15]:= ddvar[x_, n_: 1] := D[#, {x, n}] &

以下是您在帖子和评论中的一些示例.

Here are some of your examples, both from post and comments.

In[17]:= diffop =ncTimes[(1 + ddvar[x] + ncTimes[x, ddvar[y, 2]])^2, (1 +ncTimes[y, ddvar[y]])^2]

In[17]:= diffop = ncTimes[(1 + ddvar[x] + ncTimes[x, ddvar[y, 2]])^2, (1 + ncTimes[y, ddvar[y]])^2]

Out[17]= ncTimes[(1 + (D[#1, {x, 1}] & ) +ncTimes[x, D[#1, {y, 2}] &])^2,(1 + ncTimes[y, D[#1, {y, 1}] & ])^2]

Out[17]= ncTimes[(1 + (D[#1, {x, 1}] & ) + ncTimes[x, D[#1, {y, 2}] & ])^2, (1 + ncTimes[y, D[#1, {y, 1}] & ])^2]

将此运算符应用于 f[x,y].

Apply this operator to f[x,y].

In[25]:= DifferenceOperate[diffop, f[x, y]]

In[25]:= differentialOperate[diffop, f[x, y]]

输出[25]= f[x, y] + 3*y*Derivative[0, 1][f][x, y] +9*导数[0, 2][f][x, y] +18*x*Derivative[0, 2][f][x, y] + y^2*Derivative[0, 2][f][x, y] +7*y*Derivative[0, 3][f][x, y] + 14*x*y*Derivative[0, 3][f][x, y] +25*x^2*Derivative[0, 4][f][x, y] + y^2*Derivative[0, 4][f][x, y] +2*x*y^2*Derivative[0, 4][f][x, y] +11*x^2*y*Derivative[0, 5][f][x, y] +x^2*y^2*Derivative[0, 6][f][x, y] + 2*Derivative[1, 0][f][x, y] +6*y*Derivative[1, 1][f][x, y] + 18*x*Derivative[1, 2][f][x, y] +2*y^2*Derivative[1, 2][f][x, y] +14*x*y*导数[1, 3][f][x, y] +2*x*y^2*Derivative[1, 4][f][x, y] + Derivative[2, 0][f][x, y] +3*y*Derivative[2, 1][f][x, y] + y^2*Derivative[2, 2][f][x, y]

Out[25]= f[x, y] + 3*y*Derivative[0, 1][f][x, y] + 9*Derivative[0, 2][f][x, y] + 18*x*Derivative[0, 2][f][x, y] + y^2*Derivative[0, 2][f][x, y] + 7*y*Derivative[0, 3][f][x, y] + 14*x*y*Derivative[0, 3][f][x, y] + 25*x^2*Derivative[0, 4][f][x, y] + y^2*Derivative[0, 4][f][x, y] + 2*x*y^2*Derivative[0, 4][f][x, y] + 11*x^2*y*Derivative[0, 5][f][x, y] + x^2*y^2*Derivative[0, 6][f][x, y] + 2*Derivative[1, 0][f][x, y] + 6*y*Derivative[1, 1][f][x, y] + 18*x*Derivative[1, 2][f][x, y] + 2*y^2*Derivative[1, 2][f][x, y] + 14*x*y*Derivative[1, 3][f][x, y] + 2*x*y^2*Derivative[1, 4][f][x, y] + Derivative[2, 0][f][x, y] + 3*y*Derivative[2, 1][f][x, y] + y^2*Derivative[2, 2][f][x, y]

那些边缘情况.

In[26]:=differentialOperate[ncTimes[1, 1], f[t]]

In[26]:= differentialOperate[ncTimes[1, 1], f[t]]

输出[26]= f[t]

Out[26]= f[t]

我们可以将符号声明为标量.

We can declare a symbol to be scalar.

In[28]:= scalarQ[a] ^= True;

In[28]:= scalarQ[a] ^= True;

现在它将作为一个简单的乘数被拉出.

Now it will get pulled out as a simple multiplier.

In[29]:= differenceOperate[ncTimes[a, b], f[t]]

In[29]:= differentialOperate[ncTimes[a, b], f[t]]

出[29]= a b f[t]

Out[29]= a b f[t]

---结束编辑---

丹尼尔·利希布劳Wolfram 研究

Daniel Lichtblau Wolfram Research

这篇关于如何在mathematica中扩展微分运算符的算术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆