Write a function bisect f a b tol that employs the bisection

Write a function bisect (f, a, b, tol) that employs the bisection method for finding a value of x such that f(x) = 0. The first input is a handle to a function computing f. Assuming that f is continous and that f(a) f(b)

Solution

function r = bisection( f, a, b, tol ) if ( f(a) == 0 ) r = a; return; elseif ( f(b) == 0 ) r = b; return; elseif ( f(a) * f(b) > 0 ) error( \'f(a) and f(b) do not have opposite signs\' ); end while(abs(f(a) < 2*tol) c = (a + b)/2; if ( f(c) == 0 ) r = c; return; elseif ( f(c)*f(a) < 0 ) b = c; else a = c; end end function y = f(x) y = x.^3 - 2;
 Write a function bisect (f, a, b, tol) that employs the bisection method for finding a value of x such that f(x) = 0. The first input is a handle to a function

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site