{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

New Word 2007 Document (27)

# New Word 2007 Document (27) - c = a b 2 approx_root = c fc...

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

A Bisection Program Here is a MATLAB function that carries out the bisection algorithm for our cosy function. The endpoints of the initial interval are variables that you specify when you invoke the function. function approx_root = bisect ( a, b ) % bisect finds an approximate root of the function cosy using bisection fa = cosy(a); fb = cosy(b); while ( abs ( b - a ) > 0.000001 )
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: c = ( a + b ) / 2; approx_root = c; fc = cosy(c); % % What follows is just a nice way to print out a little table. It does not add to the algorithm itself, it only makes it easier to see what is going on at runtime. % [ a, c, b;fa, fc, fb ] if ( sign(fb) * sign(fc) <= 0 ) a = c; fa = fc; else b = c; fb = fc; end end...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online