function xx=bisection1(f,a,b,MaxIterates) % Basic bisection that returns all the values in the iteration. y1=f(a); y2=f(b); for k=1:MaxIterates xx(k)=0.5*(a+b); y3=f(xx(k)); %Very special case: if y3==0 fprintf('Whoo hoo! Root found exactly after %d iterations...\n',k); return end %Reset the interval if y1*y3<0 b=xx(k); y2=y3; else a=xx(k); y1=y3; end end xx(MaxIterates+1)=0.5*(a+b);