How to differentiate with dependent variables

39 views
Skip to first unread message

Smart Manoj

unread,
Mar 11, 2018, 6:32:38 AM3/11/18
to sympy
from sympy import *
var('x y')
eqn=x**2+y
print(eqn.diff(x)) # 2*x but required 2*x+y'

Jashan

unread,
Mar 11, 2018, 11:25:48 AM3/11/18
to sympy
Manoj,

you have to initialize y as a function of x rather than a Symbol

>>> var('x')
>>> y = Function('y')(x)
>>> eqn = x**2 + y
>>> diff(eqn, x)
2*x + Derivative(y(x), x)


Reply all
Reply to author
Forward
0 new messages