So I have to write a python script for finding the root of a function using Newton's Method, and my code isn't computing a float when evaluating the derivative at a point, it's only evaluating the sin(x) part, leaving e^x and log(2) as they are. I'm stuck, please help. This is my code so far:
from sympy import *
x=symbols('x')
f="(e**x)+(2**(-x))+2*cos(x) - 6"
func=sympify(f)
fdiff=Derivative(func, x) #this returns an expression for the derivative
val=fdiff.doit().subs({x: 0.4})
print(val) #this should output 0.187681.... instead it returns another expression
PS: evalf doesn't work either, neither does subs(x, 0.4)
Using
E
instead ofe
:Note the different script for
e
.With your expression
To use this, you have to include both
e
andx
in the subs.