Python Partial Derivatives
I am interested in calculating partial derivatives in Python. I've seen functions that calculate derivatives for individual variables, but not others.
It would be great to find something that did the following
f(x,y,z) = 4xy + xsin(z)+ x^3 + z^8y
part_deriv(function = f, variable = x)
output = 4y + sin(z) +3x^2
Has anyone seen anything like this?
+3
cnrk
source
to share
2 answers
use sympy
>>> from sympy import symbols, diff
>>> x, y, z = symbols('x y z', real=True)
>>> f = 4*x*y + x*sin(z) + x**3 + z**8*y
>>> diff(f, x)
4*y + sin(z) + 3*x**2
+6
wtayyeb
source
to share
Use sympy
From the Docs :
>>> diff(sin(x)*exp(x), x)
x x
β― β
sin(x) + β― β
cos(x)
and for your example:
>>> diff(4*x*y + x*sin(z)+ x**3 + z**8*y,x)
3x**2+4*y+sin(z)
+2
Nitish
source
to share