%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))); iterMax=5; if ((f(a)*f(b))< 0) for iter=1:iterMax 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