I'm a newbie learning python. I have a question, can you guys help me? This is my code:
from sympy import *
def test(f, g, a):
f1 = f.subs(x, g)
df1 = diff(f1, x).subs(x, a)
return df1
print(test((2*(x**2) + abs(x + 1)), (x - 1), -1))
Result: -Subs(Derivative(re(x), x), x, -1) - 8
I'm taking the derivative of f(g(x)) with: f = 2(x^2) + abs(x + 1), g = x - 1 and x = -1. When I use diff to calculate the result is -Subs(Derivative(re(x), x), x, -1) - 8, but when I use the formula lim x->x0 (f(x) - f(x0))/(x - x0) I got result is -9. I also tried using a calculator to calculate and the result -9 is the correct result. Is there a way to make diff return -9? Anyone have any help or can give some pointers?
Thanks!