user1772257
user1772257

Reputation: 323

Differential operator in Sympy or in Wxmaxima

Is it possible to generate linear differential operator with open source softwares such as sympy or wxmaxima and apply it to a function. For example, let differential operator L be:

L = d^2/dx^2 + d^2/dy^2 +d/dx

and

f = x^2*y^3

For example I want to apply L/3 + L^2/3^2 +L^3/3^3 to f. In mathematica this can be done as in following link: https://mathematica.stackexchange.com/questions/72433/polynomial-expansion-of-operator

Upvotes: 1

Views: 347

Answers (2)

smichr
smichr

Reputation: 19115

As suggested, but you might consider a recursive definition:

>>> def L(n, f):
...     if n==1:
...         return diff(f, x) + diff(f, x, 2) # for example
...     return L(n-1, L(1,f))
>>> L(2, x**2+y/x)
2 + 2*y/x**3 + 6*y*(-1 + 4/x)/x**4 - 6*y/x**4

Upvotes: 3

user6655984
user6655984

Reputation:

SymPy does not have a "differential operator" kind of objects. But a Python function performing differentiation does exactly what you describe.

>>> L = lambda f: f.diff(x, 2) + f.diff(y, 2) + f.diff(x)
>>> L(x**2*y**3)
6*x**2*y + 2*x*y**3 + 2*y**3

Upvotes: 1

Related Questions