%%% Fixed point iteration algorithm to solve f(x)=x^3+4x^2-10=0 in [1,2]
%%% using the function g(x)=(1/2)*(10-x^3)^(1/2) from Example 3, pages 57-58

%%% initial approximation p0 
p0=1.5;

%%% tolerance TOL
TOL=10^(-5); 

%%% here a different stoping criteria is used: if |f(p)| < TOL 

%%% maximum number of iterations N
N=100; 

for k=1:N

   p = (0.5) * (10-(p0)^3)^(0.5);

   f=p^3+4*p^2-10; 

   if abs(f) > TOL
           p0=p; 
           fprintf('iter =%3d    p = %15.8e   f(p) = %15.8e \n', k, p, f);
   else 
           k=N;
   end
    
end

