chap 3 hw - function bisection(func,xl,xu,es,maxit%Problem...

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

View Full Document Right Arrow Icon
function bisection(func,xl,xu,es,maxit) %Problem 5.8 using bisection method test=func(xl)*func(xu); if test>0,error( 'no sign change' ), end iteration=0; xr=xl; disp( ' i xl xu xr f(xl) f(xr) f(xr)f(xl) ea' ); while (1) xrold=xr; xr=(xl+xu)/2; iteration=iteration+1; if xr~=0, ea=abs((xr-xrold)/xr); end test=func(xl)*func(xr); fprintf( ' %1d %6.5f %6.5f %6.5f %6.5f %6.5f %6.5f %4.2f\n' ,iteration, xl,xu,xr,func(xl),func(xr), test, ea) if test<0 xu=xr; elseif test>0 xl=xr; else ea=0; end if ea<=es||iteration>=maxit, break , end end
Background image of page 1

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

View Full DocumentRight Arrow Icon
falseposition(func,xl,xu,es,maxit) %Problem 5.8 falseposition test=func(xl)*func(xu); if test>0,error( 'no sign change' ), end iteration=0; xr=xl; disp( ' i xl xu f(xl) f(xu) xr f(xr) f(xl)f(xr) ea' ); while (1) xrold=xr; xr=xu-(func(xu)*(xl-xu))/(func(xl)-func(xu)); iteration=iteration+1; if xr~=0, ea=abs((xr-xrold)/xr); end test=func(xl)*func(xr); fprintf( ' %1d %2.1f %6.5f %6.5f %6.5f %6.5f %6.5f %6.5f %5.3f\n' ,iteration, xl,xu,func(xl),func(xu),xr,func(xr),
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/27/2011 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

Page1 / 9

chap 3 hw - function bisection(func,xl,xu,es,maxit%Problem...

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

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