In Haskell, I am using the following function to find the root of a polynomial:
polyNewton :: (Fractional a, Ord a) => Poly a -> a -> a`
polyNewton p s = if (abs(polyValue p s) <= (0 + 1e-10)) then s else polyNewton
p (s - (polyValue p s) / (polyValue (polyDeriv p) s))
where polyValue is a function that finds the y-value of a polynomial p, an x-value x, and polyDeriv is a function that returns the derivative of a polynomial p.
This code works quite well for the majority of cases, except where the polynomial does not have any actual roots (the function is above the x-axis) or if a bad initial guess is given. Is there anyway to determine if Newton's Method will fail beforehand so that my function does not run indefinitely?