function [x,iter]=hw7extra(int,tol) % bisection method for x^2-2=0 % int is the initial interval entered as [a,b] % tol is the tolerance, basically tells you to stop when the interval is shorter than tol iter=0; while (int(2)-int(1)>tol) iter=iter+1; x=(int(2)-int(1))/2+int(1); if (int(1)^2-2>0 & int(2)^2-2<0) if (x^2-2>0) int=[x,int(2)]; else int=[int(1),x]; end elseif (int(1)^2-2<0 & int(2)^2-2>0) if (x^2-2>0) int=[int(1),x]; else int=[x,int(2)]; end else disp('bad initial interval') break end end