'Hw 2, Computational Problem (c): Newton'

clear all

p = 0.4 
iteration = 0;
nmax = 10;

ptrue = atan(6)/pi

while (iteration <= nmax )

   iteration = iteration + 1;
   
   f = tan(pi*p)-6;
   fprime = pi / (cos(pi*p))^2;
       
   p = p - f/fprime;
   fprintf(1,'iteration # %3d ',iteration);  fprintf(1,', p = %15.8e',p);
   fprintf(1,', |p-ptrue| = %15.8e',abs(p-ptrue));
   fprintf(1,', f(p) = %15.8e', f);  fprintf(1,'\n');

end
