'Hw 2, Computational Problem (b): Secant'

clear all

p0 = 0.4 
p1 = 0.48
iteration = 0;
nmax = 10;

ptrue = atan(6)/pi

while (iteration <= nmax )

   iteration = iteration + 1;
   
   f0 = tan(pi*p0)-6;
   f1 = tan(pi*p1)-6;
       
   p2 = p1 - f1*(p1-p0)/(f1-f0);
   f2 = tan(pi*p2)-6;
   
   fprintf(1,'iteration # %3d ',iteration);  fprintf(1,', p = %15.8e',p2);
   fprintf(1,', |p-ptrue| = %15.8e',abs(p2-ptrue));
   fprintf(1,', f(p) = %15.8e', f2);  fprintf(1,'\n');
   
   p0 = p1;
   p1 = p2;

end
