1

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?

Jason Hu
  • 6,239
  • 1
  • 20
  • 41
Jack Buckley
  • 161
  • 6
  • 3
    how do you determine if it fails or not in other languages than haskell? – Jason Hu Nov 03 '17 at 20:22
  • I know that if a polynomial has an odd degree, it will cross the x-axis. I am not sure how to tell if an even degreed polynomial will cross the x-axis. I can think of using the Intermediate Value Theorem but over which domain? – Jack Buckley Nov 03 '17 at 20:27
  • 5
    I'm voting to close this question as off-topic because it's really about math rather than programming. You can try asking on math.stackexchange.com. If you have trouble implementing the answer, you can come back here. – dfeuer Nov 03 '17 at 20:34
  • your answer shows you actually did not manage to handle the odd case either. Newton method requires a initial value to begin with, but how do you set the initial value? you are guaranteed to get a solution in odd case, but if there are many solutions, which one are you looking for? – Jason Hu Nov 03 '17 at 20:34

1 Answers1

8

To determine roughly where a polynomial of degree N has its roots – if any – it is sufficient to know all its extrema, because you must have exactly one root

  • between any adjacent negative minimum and positive maximum
  • to the left of the leftmost extremum, if it's a negative minimum or positive maximum
  • to the right of the rightmost extremum, if it's a negative minimum or positive maximum

The extrema are themselves roots of the derivative, which is conveniently a polynomial of degree N–1, so you can go down recursively until you get to the linear (or quadratic) case, where it's trivial to find the roots (exactly, in fact).

leftaroundabout
  • 117,950
  • 5
  • 174
  • 319
  • How can you use this information to find appropriate initial values to get Newton's method to converge to each root? – dfeuer Nov 04 '17 at 20:59
  • @dfeuer as I said, you start out with _intervals_ (between the extrema) in which you know each root must lie. You then start Newton on the midpoint of each interval, but restricted so it can never leave the interval. What this means in practice is, whenever _xᵢ_ + _yᵢ_ / _xᵢ'_ lies outside the interval, you instead do a simple bisection step to refine that interval, until the function is straight enough on the remaining interval so that Newton with its quadratic convergence kicks in. – leftaroundabout Nov 04 '17 at 21:07