function[x e] =mybisect(f,a,b,n)% function [x e] = mybisect(f,a,b,n)% Does n iterations of the bisection method for a function f% Inputs: f -- an inline function% a,b -- left and right edges of the interval% n -- the number of bisections to do.% Outputs: x -- the estimated solution of f(x) = 0% e -- an upper bound on the errorformatlongc=f(a);d=f(b);ifc*d>0.0error('Function has same sign at both endpoints.')enddisp(' x y')fori=1:nx=(a+b)/2;y=f(x);disp([xy])ify==0.0% solved the equation exactlye=0;break% jumps out of the for loopendifc*y<0b=x;elsea=x;endende=(b-a)/2;