%  SAMPLE ALGORITHM TO FIND THE DEGREE OF TAYLOR POLY NEEDED TO ACHIEVE
% A SPECIFIED TOLERANCE TO APPROX. LN(X)
% 
%  Find the first term of the alternating series which is smaller than TOL
% 
%  INPUT:   x;
%           TOL;
%           Maximum number of iterations M
% 
%  Output:  The number of iterations required to achieve goal, or a failure message.
%
% Example by Tim, Mike and Chris
 fprintf(1,'Find the degree of the Taylor Polynomial that has an error within a tolerance.\n');
 TOL = 0;
 fprintf(1,'Input the value of x:\n');
 x = input(' ');
 fprintf(1,'Input the desired tolerance of the polynomial:\n');
 TOL = input(' ');
 fprintf(1,'Input the maximum number of iterations to be executed:\n');
 M = input(' ');
 N = 1;
 y = x - 1;
 S = 0;
 power = y;
 term = y;
 sign = -1;
 while (N<=M)
     sign = -1*sign;
     S = S + (sign*term);
     power = power*y;
     term = power/(N + 1);
     if (abs(term)<TOL)
         fprintf(1,'N = %11.8f\n', N);
         return;
     end;
     N = N + 1;
 end;
 
 if (abs(term)>=TOL)
     fprintf(1,'Method Failed!\n');
 end;