function p = bisection(a,b) % provide the equation you want to solve with R.H.S = 0 form. % Write the L.H.S by using inline function % Give initial guesses. % Solves it by method of bisection. % A very simple code. But may come handy t = f(a)*f(b); k=0; if t >0 disp('Wrong choice bro') else p = (a + b)/2; err = abs(f(p)); while err > 1e-14 if f(a)*f(p)<0 b = p; else a = p; end p = (a + b)/2; k = k+1, err = abs(f(p)); end end