New Word 2007 Document (27)

New Word 2007 Document (27) - c = ( a + b ) / 2;...

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

View Full Document Right Arrow Icon
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 )
Background image of page 1
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

This document was uploaded on 05/07/2010.

Ask a homework question - tutors are online