% Script to solve a system of nonlinear equations by Newton's method.

% Define the problem
fun = @newton_ex;      % Handle to a function [f, J] = fun(x)
X = [0.5; 0.5];        % Initial guess
tol = 1e-10;           % Tolerance
maxiter = 100;         % Maximum number of iterations
H = [1; 1];            % Initial update value
n = 1;                 % Iteration counter
% Newton loop
while norm(H) > tol && n < maxiter
    [F, J] = feval(fun, X);
    H = -J \ F;
    X = X + H;
    n = n + 1;
end

X
