I am trying to plot Ramanujan's Pi formula and observe how the errors are reducing as the number of iterations increases. However MATLAB simply outputs 0 after the first iteration even when I put the value of digits() to around 300. I know the formula doesn't calculate pi to a 100 decimals after the first iteration, in fact it's an additonal 8 decimal places per iteration after the first, yet it continues to output 0.0 as the value of the function – value of pi calculated to 300 digits. How can I fix this?
This is my code for the formula and the error function (I am using disp() at the end just to test the code).
% Ramanujan's Formula Plot %
rconst = sqrt(8)/9801;rsum = 0;rlim = 100;plt3= 1:(rlim+1);for n= 0:rlim ctr = 1; f4n = factorial(4*n); fn = factorial(n); num = (f4n * (1103+26390*n)); den = ((fn^4) * 396^(4*n)); rcalc = (num/den); rtemp = (rconst * rcalc); rsum = (rsum + rtemp); rpi = (1/rsum); plt3(n+1) = vpa(rpi); ctr = ctr +1; endplot(plt3);for ii = 1:41 var = abs(plt3(ii) - vpa(pi,334)); phi = sym(var); disp(vpa(phi,334));end
Best Answer