I'm working a program which implements Newton's method on an m file containing the system of equations and Jacobians
function x = fun(x,mode)
% compute F(x)
if mode == 1
x = [ 3*x(1)^2 + 5*x(2)^2 + x(2) - 1;
x(1)^2 - 6*x(1) - 3*x(2) - 2];
end
% compute the Jacobian DF(x)
if mode == 2
x = [ 1*x(1) 3*x(2)+1; 6*x(1)-2 -2];
end
return;
Here is the computational file that I've started:
results.stat = 0;
if nargin == 3
epsilon = param.epsilon;
nMax = param.nMax;
else
epsilon = 1.0e-8;
nMax = 500;
end
F = fun(x,1)
J = fun(x,2)
end
for k = 1:nMax
dx = -J\f
x=x+dx
I eventually want to check convergence and save the errors norm and also check if the max iteration count is reached without convergence. Does this look ok so far?