% Script to solve a system of nonlinear equations by
% Newtons method.
% It is probably more useful if you rewrite it into a function.
% Define the problem.
fun = @newton_ex; % handle to a function [f,J]=fun(x)
x = [1;1;1]; % Initial guess.
tol = 1.e-10; % Tolerance
% Newton loop.
for n=1:10
[F,J] = feval(fun,x);
d = -J\F;
x = x+d
if norm(d)<=tol
break;
end
end