%f = inline('cos(x)-x.^3'); f = inline('x.^3 + 4*x.^2 - 10'); a=1; b=2; x0 =0; x1=1; x2 = x1-((f(x1)*(x1-x0))/(f(x1)-f(x0))); iter=0; eps=10^(-6); if ((f(a)*f(b))< 0) while (abs(x2-x1)>eps) iter=iter+1; x0=x1; x1=x2; x2 = x1-((f(x1)*(x1-x0))/(f(x1)-f(x0))); 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