I'm trying to find the root by Newton-Raphson method and encounter the following error in the while loop; other related questions deal with Sympy objects but the two variables involved in the error are not Sympy objects. Code below -
import math
import sympy as sym
import scipy, pylab
from sympy import Symbol, symbols
x=Symbol('x')
a=float(input("enter initial guess root"))
n=float(input("enter tolerance"))
def solve (x) : # function whose roots need to be found out
return (x*math.tan(x) - math.sqrt(225-x*x))
def differ (a) : # function to differentiate
ans=sym.diff((x)*sym.tan(x) - sym.sqrt(225 - x*x))
return (ans)
i=2.0
while i > n : # standard Newton-Raphson condition **(causing error)**
root=a-solve(a)/differ(a)
i=abs(a-root)
a=root
print (root) # print final root
Output with error -
enter initial guess root 2
enter tolerance 0.1
Traceback (most recent call last):
File "try2.py", line 22, in <module>
while i > n :
File "/Users/uditashukla/opt/anaconda3/lib/python3.8/site-packages/sympy/core/relational.py", line 384, in __nonzero__
raise TypeError("cannot determine truth value of Relational")
TypeError: cannot determine truth value of Relational