function y=newton(func,x1) % Newton method % function y=newton(func,x1) % (c) 2007 Alain Hebert, Ecole Polytechnique de Montreal f=feval(func,x1) ; x2=x1-f{2}\f{1} ; iter=0 ; while (norm(abs(x1-x2)) >= 1.0e-6) & (norm(abs(f{1})) >= 1.0e-6) iter=iter+1 ; if iter > 20 error('exceeded number of iterations') end fprintf(1,'%d f(x2): %2.1e \n', iter, norm(abs(f{1}))); x1=x2; f=feval(func,x1) ; x2=x1-f{2}\f{1} ; end y=x2;