python - Exact user defined expressions in Sympy derivatives -
i using sympy calculate derivative of complicated potential. have defined x, y, d0, e, c, k, d, b sympy symbols. go on following definitions:
import sympy sm x, y, d0, e, c, k, d, b = sm.symbols("x, y, d0, e, c, k, d, b") phi = sm.atan2(y,x) d = d0 + e*d0*sm.sin(k*phi) rho = sm.sqrt(x**2 + y**2) u = (2**b)/((2*d-d)**b)*(d - rho)**b the symbol "u" stands 2d potential.
now when differentiate vs. x using:
sm.simplify(u.diff(x)) as can see, in answer there explicitly full expression e.g. d : d0 + e*d0*sin(k*phi) . also, instead of sin(phi) sin(atan2(x,y) , same happens of defined expressions.
is there way result automatically show definitions instead of long versions, without having need use subs method every single user-defined variable?
e.g. instead of d0 + e*d0*sin(k*phi) sympy automatically uses symbol d?
when write phi = sm.atan2(y,x), assigns python variable result of atan2(y, x). if want phi symbol, have define way
phi = symbols('phi') and substitute phi in atan2(y, x) later.
u.subs(phi, atan2(y, x)) this worth reading regarding this.

Comments
Post a Comment