Domanda

Sympy sometimes automatically generates substitutions in my experessions:

How can I prevent this? Or, how can I remove the substitution from the expression?

from sympy import *
R, T = symbols('R T', cls=Function)
u = symbols('u', cls=Function)
x, y, z= symbols('x y z')

R(u(x,y)).diff(x)

gives

Derivative(u(x, y), x)*Subs(Derivative(R(_xi_1), _xi_1), (_xi_1,), (u(x, y),))

I'd like to have

Derivative(u(x, y), x)*Derivative(R(u(x, y), (u(x, y)))

PS: http://docs.sympy.org/latest/modules/core.html#subs says "When evaluating derivatives at a point that is not a symbol, a Subs object is returned."

È stato utile?

Soluzione

The following will give you what you ask for

>>> s=R(u(x,y)).diff(x)
>>> s.replace(Subs, lambda a,b,c: a.xreplace(dict(zip(b,c))))

(It will revert to a Subs instance if you apply the doit method.)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top