New Word 2007 Document (19)

# New Word 2007 Document (19) - itCount = 0; while ( abs ( xb...

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

Exercise 4 : Create the file bisect_cosmx1.m by typing it in yourself, by using copy-and-paste to copy it from this window 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 % M. M. Sussman % \$Date: 2005/08/23 02:19:54 \$ % \$Id: bisect_cosmx.m,v 1.7 2005/08/23 02:19:54 mike Exp \$ EPSILON = 1.0e-6; fa = cosmx(xa); fb = cosmx(xb); approxRoot= (xa + xb)/2;

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: itCount = 0; while ( abs ( xb - xa ) > EPSILON ) itCount = itCount + 1; xc = ( xa + xb ) / 2; 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 ) xa = xc; 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

## This document was uploaded on 05/07/2010.

### Page1 / 2

New Word 2007 Document (19) - itCount = 0; while ( abs ( xb...

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

View Full Document
Ask a homework question - tutors are online