function v=rawNewton(F,DF,v0); % RAWNEWTON: v=rawNewton(F,DF,v0) % A slow implementation of Newton--Raphson. In practice % the gradient matrix could be approximated by Broyden's method % and a one-dimensional search for the solution would be used. % Note the parameters [with default values]: % maxNewt [=20] max number of iterations % Ftol [=1e-8] equations F=0 should be true to this accuracy % vtol [=1e-5] v should be determined to this accuracy % CONDtol [=1e10] used to determine if DF is invertible. % % Try "F=inline('[x(1)^2+x(2)^2-4;exp(x(1))-x(2)]','x'), % DF=inline('[2*x(1), 2*x(2);exp(x(1)), -1]','x'), % rawNewton(F,DF,[1 2]', 10)" % (ELB 4/27/02) maxNewt=20; Ftol=1e-8; vtol=1e-5; CONDtol=1e10; v=v0; for j=1:maxNewt FF=feval(F,v); DFF=feval(DF,v); if cond(DFF)>CONDtol % this way of testing for invertibility is slow error(['rawNewton error: Gradient matrix close to singular'... ' at Newton step' num2str(j)]); end; dv=-DFF\ FF; % note backslash v=v+dv; if (norm(dv,inf)