{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

New Word 2007 Document (18)

# New Word 2007 Document (18) - approxRoot = xc fc = cosmx(xc...

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

function approxRoot = bisect_cosmx( xa, xb) % approxRoot = bisect_cosmx( xa, xb) uses bisection to find a % root of cosmx between xa and xb to tolerance 0.000001 % xa=left end point of interval % xb=right end point of interval % cosmx(xa) and cosmx(xb) should be of opposite signs % your name and the date EPSILON = 1.0e-6; fa = cosmx(xa); fb = cosmx(xb); approxRoot = (xb+xa)/2; itCount = 0; while ( abs ( xb - xa ) > EPSILON ) itCount = itCount + 1; xc = ( xa + xb ) / 2;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: approxRoot = xc; fc = cosmx(xc); % The following statement prints the progress of the algorithm disp(strcat('xa=',num2str(xa),', fa=',num2str(fa),', xc=',num2str(xc),. .. ', fc=',num2str(fc),', xb=',num2str(xb),', fb=',num2str(fb))) if ( fc == 0 ) break; elseif ( sign(fb) * sign(fc) <= 0 ) xa = xc; fa = fc; else xb = xc; fb = fc; end end disp(strcat('bisect_cosmx took itcount=',num2str(itCount),' steps.'))...
View Full Document

{[ snackBarMessage ]}