Robby Robby - 4 months ago 15
Python Question

Implicit differentiation with Python 3?

How can we derivate a implicit equation in Python 3?

Example

x^2+y^2=25
differentiation is:
dy/dx=-x/y
, when try this:

from sympy import *

init_printing(use_unicode=True)

x = symbols('x')
y = Function('y')(x)

eq = x**2+y**2-25
sol = diff(eq, x)
print(sol)


But it shows:

2*x + 2*y(x)*Derivative(y(x), x)


How can get
-x/y
?

Answer

You have the differential equation, so you can rearrange it using solve:

solve(sol, diff(y, x, 1))
Comments