Solve the equation by the method of tangents (Newton's method). Gives an error message
TypeError: can't convert complex to float
in the line x = x_prev - (func(x_prev)/diff(func(x_prev)))
Here is the code:
from sympy import diff def func(x): return (math.exp(x)) + (x ** 3) - 2 def perform_tangent_method(a, b, eps): '''Equation solution by tangent(Newton) method''' x_prev = b while True: try: x = x_prev - (func(x_prev)/diff(func(x_prev))) except ZeroDivisionError: return 'ERROR: Zero division!' if abs(x - x_prev) <= eps: break else: x_prev = x return x