1

I have an issue with Newton(tangent) method in Matlab.

I wrote a program, that:

  1. Displays the graphic of the given function f, associated with the nonlinear equation, which solutions I need to determine(thus I let the user determine the first approximation using the graph, by choosing a point on [Ox axes that's nearest to the solution -> to the intersection of f with [Ox)
  2. Determines the solution for the equation, corresponding to the first approximation.

    But, still it isn't enough.

    Is it possible to make such a kind of test for the first approximation, introduced by user, that it would prevent Newton method from blocking(this means that there is no point of local minimum in the vecinity of the choosen first approximation) ? Thus, when something like this happens, user would know that the point choosen is wrong, because there are two tangents to the graph of function f, so the program won't give anything, but will block.

    Can you, please, suggest me something ?

wonderingdev
  • 1,132
  • 15
  • 28

1 Answers1

1

If I understand right, you are using Newton's method whose formula is:

enter image description here

As far as I remember, for convergence of Newton's method (besides the requirements of continuity) two conditions should be true:

1) Derivative of function should not be zero at any of the stages. So you can insert in your code something like:

if dfdx < 1e-4
disp('Bad starting point')
break;
end

2) The sign of derivative should not change its sign with iterations. So, insertion of something like:

derivative = temp; %save the value of old derivative in variable

%code that counts derivative for new iteration

if sign(derivative)~=sign(temp)
disp('Bad starting point')
break;
end

If you want to add something more sophisticated, you can add the check for conditions of quadratic convergence. The method is described in detail here or at Wikipedia.

Good luck

brainkz
  • 1,335
  • 10
  • 16