prodoggy4life
prodoggy4life

Reputation: 327

Issue with differentiation using sympy

I am trying to differentiate this equation using SymPy:

What I wanted to achieve is this result:

But when I type this code into to execute, it gives me this result:

Here is my current code:

import sympy as sp

# declare symbols
t = sp.Symbol('t')

deriv = sp.diff((t*(sp.cos(t)))/(1-t)**2)

# Find the derivative
sp.simplify(deriv)

Is there a way to achieve the desired result?

Upvotes: 1

Views: 77

Answers (1)

Pani
Pani

Reputation: 1377

That is the same result. Break the result you get on the "+" and you get the same thing enter image description here

Looking for the "simplest" form is not a well-defined problem and sympy can't guess which form you are looking for. You can always call sp.simplify on both the result you get and the desired answer. sympy will derive the same expression for both. In your case

result = sp.simplify(deriv)
desired = sp.simplify((-2 * t * sp.cos(t))/(t - 1)**3 + (-t * sp.sin(t) + sp.cos(t))/(t - 1)**2)
# result == desired

Upvotes: 1

Related Questions