% Newton's to solve nonlinear system of 3 equations in 3 unknowns NN = 6; x = [1 1 1]'; for n = 1:NN f = [x'*x - 4, sin(2*pi*x(1)) - x(3), x(1)^2 - x(2)]'; residuals(:,n) = f; J = [2*x(1) 2*x(2) 2*x(3); 2*pi*cos(2*pi*x(1)) 0 -1; 2*x(1) -1 0]; s = J \ (-f); x = x + s; estimates(:,n) = x; end estimates, residuals