javasolver

Newton Raphson no solution


I am using the Newton Raphson's method in order to find the root of an evaluation function in Java. I am using a while loop with the following termination condition :

while(Math.abs(eval_x / deriv_x) > epsilon)

Obviously it may create an infinite loop if the difference is bigger than epsilon. Should I replace epsilon with a bigger value or should I include a counter which breaks the while loop when attaining a specific big value ?

I would like to know how to implement a standard termination condition for the Newton's method.


Solution

  • Typically, for something like Newton's method, there are a number of termination criteria:

    1. An upper bound on the number of iterations. It is possible that the routine may get "stuck" or diverge such that if you do not find a root, you should exit after a certain max iterations.

    2. A tolerance on a change in x. This can either be relative or absolute. If the algorithm is producing a change in x below a certain value (say 1e-6) and you have not yet converged then you may be stuck at a stationary points.

    3. Speaking of stationary points, if your gradient (derivative) is below a certain tolerance you should terminate, because you may end up at a stationary point and if you are doing the one dimensional case, dividing by zero.

    4. A tolerance on the absolute value of the function. This is your ultimate measure of how close you want to be to the zero.

    Keep in mind that if you set your function value tolerance too tight, Newton's method may never produce a change in value of x sufficiently small to get you within that tolerance. Hence why you should have a stop on dx - and of course on the maximum number of iterations.