I used sympy to find derivative of a function.
𝑓(𝑥)=𝑥−5+√(4−𝑥^2)
import sympy
def f_derivative(x):
x = sympy.Symbol('x')
f = x - 5 + (4 - x**2)**0.5
derivative_f = f.diff(x)
derivative_f = sympy.lambdify(x, derivative_f)
print(derivative_f(1))
f_derivative(1)
assert f_derivative(1) - 0.42264973 < 1e-5
However, there is an error when I use assert to check
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
Please let me know how to fix it
import sympy
def f_derivative(x):
x = sympy.Symbol('x')
f = x - 5 + (4 - x**2)**0.5
derivative_f = f.diff(x)
derivative_f = sympy.lambdify(x, derivative_f)
result = derivative_f(1)
assert result - 0.42264973 < 1e-5
print(result)
f_derivative(1)
I hope helped you