I have constructed a root-finding function based on the bisection method. The function works, however, the roots it gives me aren't as accurate as I want them to be. They are off of about 1e-4 when compared to the exact roots. I don't understand how I can make it more accurate. Can someone please help. Here's my code:
function root = bisection(f,a,b,tol)if sign(f(a))==sign(f(b)) error('a and b do not bracket the root');endj = 1;while abs(0.5*(b-a)) >= tol root = 0.5*(a+b); j = j+1; if sign(f(a))==sign(f(root)) a = root; else b = root; endendend
Best Answer