my_newton - niter=0; x=x0; for i=1:max_iter xold=x;...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function [root,rhist,niter,error] = my_newton(fh,dfh,x0,tol,tol_type, . .. max_iter) switch tol_type s case 'a' termination = @(xn,xo) abs(xn-xo) <= tol; case 'r' termination = @(xn,xo) abs(xn-xo)/abs(xo) <= tol; case 'f' termination = @(xn,xo) abs(feval(fh,xn))<=tol; end e rhist=[x0];
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: niter=0; x=x0; for i=1:max_iter xold=x; x=xold-fh(x)/dfh(x); rhist=[rhist x]; niter=niter+1; if stop(x,xold)==1 break; end end switch tol_type case('a') error=abs(x-xold); case('r') error=abs(x-xold)/abs(xold); case('f') error=abs(fh(x)); end root=x;...
View Full Document

This note was uploaded on 02/18/2010 for the course ENGINEERIN 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

Ask a homework question - tutors are online