% Ramanujan8.m formula for pi by Srinivasa Ramanujan.
% The first term has 7 correct digits.
% Get 8 decimal digits per term after the first.
% We sum only the first 2 terms.
% K. Ming Leung, 02/12/04

clear; format long;

a = 9801/sqrt(8);
b = 1103;
c = 26390;
s = b;
for n=1:1
    s = s + factorial(4*n)*(b+c*n)/((factorial(n))^4*396^(4*n));
end
myPi = a/s,
error = myPi-pi,