function out=newton(x) % solve for n non linear set of equations % calls f.m and jaco.m % inputs: x initial values % outputs: out=answer vector. % note that you could also input a TOL, max no of steps,... for i=1:250 % here max no of iteration is 250 if (det(Jaco(x))==0), error('singular matrix---> NO solution can be found'), end % check if jacobian is singular y=-inv(Jaco(x))*f(x); % solves jaco(x)*y=-f(x) x=y'+x; % newton iteration (update value) val=(sum((y.^2)))^.5; % calculates ||y|| if (val<0.0001), break, end % check if it is within tolerance here: 0.0001 end % wow, I can not say more... out=x'; % output final answer