% Plot the function f x=1:0.1:10; f = inline('x-exp(sin(x))'); plot(x,f(x)), grid on %-------------------- a = 0; b = 10; iter=0; eps=1.0e-3; % _____________Apply the Bisection to find the solution __________ if ((f(a)*f(b))< 0) while (abs(b-a) > eps) x0=(a+b)/2; iter=iter+1; 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