% Plot the function f x=0:0.1:10; f = inline('x-exp(sin(x))'); plot(x,f(x)), grid on %-------------------- a = 0; b = 10; iterMax=20; % _____________Apply the Bisection to find the solution __________ if ((f(a)*f(b))< 0) for iter=1:iterMax x0=(a+b)/2; if ((f(a)*f(x0))< 0) b=x0; else a=x0; end fprintf('For iteration =%d \t , the solution is x0=%f\n',iter,x0) end fprintf('The final solution is x0 = %f \n',x0) ; else disp('There is no solution in [a,b]') end