% Newton iteration near a simple root & a double root
% Convergence is quadratic for simple root
% Convergence is linear for double root
% See  example 5.11 on p.231 of Heath
% NewtonDoubleRoot.m
% function 1 has simple roots at x=1 & -1: f1(x)=x^2-1         
% function 2 has double root at x=1:       f2(x)=x^2-2*x+1     
% initial guess:    x0=3
% tolerance:        tol=1e-6
% K. Ming Leung, 02/13/03

clear all; format long; tol=1e-6; 
x1=4.1; x2=0.4; loop=0;
disp([loop x1 x2]);
for loop=1:5
    f1x=x1*x1-1;        f2x=sin(x2*x2-2*x2+1);
    f1p=2*x1;           f2p=cos(x2*x2-2*x2+1)*(2*x2-2);
    x1=x1-f1x/f1p;      x2=x2-2*f2x/f2p;
    disp([loop x1 x2]);
end;


