Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implicit Differentiation Sympy

I've been doing derivatives in sympy, and I didn't know how that would syntactically be written. I tried looking it up, but none of the solutions made sense. For example, if I'm trying to differentiate x**5 + y**2 + z**4 = 8xyz by computation, how would I do that? Would z be a symbol, or a function like in regular derivatives? Thank you.

like image 789
MANA624 Avatar asked Mar 13 '23 06:03

MANA624


2 Answers

For two variables you can use idiff.

In your case, the simplest way is to set x and y to be functions of z, like

x = Function('x')(z)
y = Function('y')(z)

Then normal diff(expr, z) will take the derivative correctly.

like image 180
asmeurer Avatar answered Mar 23 '23 19:03

asmeurer


You commented you used idiff, here is the corresponding code for those who want to know:

from sympy import symbols, idiff, simplify

x, y, z = symbols('x y z')
ex = x**5 + y**2 + z**4 - 8*x*y*z
ex_d = simplify(idiff(ex,(x,y),z))
display(ex_d)

enter image description here

In idiff(ex,(x,y),z), (x,y) are the dependent variables, and z the variable the derivative is being taken with respect to.

like image 27
mins Avatar answered Mar 23 '23 19:03

mins