%
%   SERIES_2.M   Evaluate an infinite series 
%
%   Evaluate infinite series: S = sum(x^(k-1)) for k = 1 to infinity...
%
%   Note: This series converges to 1/(1-x) for |x| < 1. For x = 0.8, this gives S = 5   
%
%   Prepared by J.R White, UMass-Lowell (last update: Sept. 2017)
%

      S = 0;  k = 1;  x = 0.8;
      rerr = 1.0;   tol = 1e-5;
      while rerr > tol
        Tk = x^(k-1);
        S = S + Tk;
        rerr = abs(Tk/S);
        k = k+1;
      end
      format long e
      disp('Estimate of infinite series:'), disp(S)
      disp('The exact result is:'), disp(1/(1-x))
%
%   end of program
