'Hw 2, Theoretical Problem 2: Secant'

clear all

p0 = -1; p1 = 0;
iteration = 0;
nmax = 10;

while (iteration <= nmax )

   iteration = iteration + 1;
   
   f0 = -p0^3 - cos(p0);
   f1 = -p1^3 - cos(p1);
       
   p2 = p1 - f1*(p1-p0)/(f1-f0);
   fp = -p2^3 - cos(p2);
   
   fprintf(1,'iteration # %3d ',iteration);  fprintf(1,', p = %15.8e',p2);
   fprintf(1,', f(p) = %15.8e', fp);  fprintf(1,'\n');
   
   p0 = p1;
   p1 = p2;

end

