my_bisection - if fx1*fn < 0 x2 = xn; else x1 = xn; end...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
function [root,rhist,niter,error] = my_bisection(fh,x1,x2,tol,tol_type,. .. max_iter) switch tol_type s case 'a' termination = @(xo,xn) abs(xn-xo) <= tol case 'r' termination = @(xo,xn) abs(xn-xo)/abs(xn) <= tol case 'f' termination = @(xo,xn) abs(feval(fh,xo)) <= tol end e fx1 = feval(fh,x1); fx2 = feval(fh,x2); rhist = []; xn = (x1+x2)/2; fn = feval(fh,xn); f for k = 1:max_iter
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if fx1*fn < 0 x2 = xn; else x1 = xn; end fx1 = feval(fh,x1); fx2 = feval(fh,x2); xo = xn; xn = (x1+x2)/2; rhist = [rhist xm]; niter = length(rhist); if termination(xo,xn) == 1 break; end end e switch tol_type case 'a' error = abs(xn-xo); case 'r' error = abs(xn-xo)/abs(xn); case 'f' error = abs(feval(fh,xo)); end...
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.

Page1 / 2

my_bisection - if fx1*fn < 0 x2 = xn; else x1 = xn; end...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online