Topic 10.3: Newton's Method (Matlab)

Contents Previous Chapter Start of Chapter Previous Topic Introduction Notes Theory HOWTO Examples Engineering Error Questions Matlab Maple Next Topic Next Chapter

Finding a root of f(x) = cos(x):

eps_step = 1e-5;
eps_abs = 1e-5;
N = 100;
x = 0.2;

for i=1:N
    xn = x - cos(x)/( -sin(x) );

    if abs( x - xn ) < eps_step && abs( cos( xn ) ) < eps_abs
       break;
    elseif i == N
       error( 'Newton\'s method did not converge' );
    end

    x = xn;
end

xn
        

What happens if you start with smaller values of x? Why?

Copyright ©2005 by Douglas Wilhelm Harder. All rights reserved.