Example for Newton Method

We want to find such that .

Define function

f = @(x) [2*x(1)+x(1)*x(2)-2 ; 2*x(2)-x(1)*x(2)^2-2 ];

Define Jacobian

fp = @(x) [2+x(2), x(1); -x(2)^2, 2-2*x(1)*x(2) ];

Perform Newton iteration

We start with the initial guess .
x = [0;0]; % initial guess
xs = [.5; 2]; % solution (used to print errors below)
for j=1:9
b = f(x); % evaluate f
A = fp(x); % evaluate Jacobian matrix
d = -A\b; % solve linear system A d = -b
x = x + d;
error = norm(x-xs,Inf);
fprintf('step %g: x = [ %-17.15g; %-17.15g], error = %8.3e\n',j,x,error)
end
step 1: x = [ 1 ; 1 ], error = 1.000e+00 step 2: x = [ 0 ; 3 ], error = 1.000e+00 step 3: x = [ 0.4 ; 2.8 ], error = 8.000e-01 step 4: x = [ 0.483870967741935; 1.99354838709677 ], error = 1.613e-02 step 5: x = [ 0.50009892401114 ; 1.99939860092483 ], error = 6.014e-04 step 6: x = [ 0.499999985726356; 1.99999999518732 ], error = 1.427e-08 step 7: x = [ 0.5 ; 2 ], error = 0.000e+00 step 8: x = [ 0.5 ; 2 ], error = 0.000e+00 step 9: x = [ 0.5 ; 2 ], error = 0.000e+00
We see that the errors decrease like , i.e. we have convergence of order 2.