I wanted to solve a function being close to 0.
I tried using the newton function in the Scipy package, but the tolerance seems to apply to the input and not the function of the input:
from scipy.optimise import newton
fn = lambda x: x*x-60
res = newton(fn, 0, tol=0.1, maxiter=10000)
print(res)
print(fn(res))
res
is close to 0, and fn(res)
is about -60.
It looks like newton()
stopped because it found two x values which are bounding the solution and within the tolerance.
Is that correct that the tolerance is on x
and not fn(x)
?
That seems very counterintuitive to me.
- SciPy reference on
scipy.optimize.newton
: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.newton.html