I have the following equation, like this:
y = 3x2 + x
Then, I want to differentiate the both side w.r.t the variable t
with sympy
. I try to implement it in the following code in JupyterNotebook
:
>>> import sympy as sp
>>> x, y, t = sp.symbols('x y t', real=True)
>>> eq = sp.Eq(y, 3 * x **2 + x)
>>>
>>> expr1 = eq.lhs
>>> expr1
>>> expr1.diff(t)
0
>>>
>>> expr2 = eq.rhs
>>> expr2
3^2+
>>> expr2.diff(t)
0
As the result, sympy
will treat the symbol x
and y
as a constant. However, the ideal result I want should be the same as the result derived manually like this:
y = 3x2 + x
d/dt (y) = d/dt (3x2 + x)
dy/dt = 6 • x • dx/dt + 1 • dx/dt
dy/dt = (6x + 1) • dx/dt
How can I do the derivative operation on a expression with a specific symbol which is not a free symbol in the expression?