Comparing two series to calculate pi

Many series are used to calculate the value of pi.  In this blog, we compare two series, one by Gregory and another by Ramanujan.

Here is a MATLAB program that does the comparison for you.  The MATLAB program can be downloaded as a Mfile (better to download it, as single quotes from the web-post do not translate correctly with the MATLAB editor).  The html file showing the mfile and the command window output is also available.

%% COMPARING TWO SERIES FOR VALUE OF PI
% Language : Matlab 2007a
% Authors : Autar Kaw
% Last Revised : October 30, 2008
% Abstract: This program compares results for the value of
% pi using a) Gregory series and b) Ramanajun series
clc
clear all
clf
format long
disp(‘This program compares results for the value of’)
disp(‘pi using a) Gregory series and b) Ramanajun series’)
disp(‘  ‘)
disp(‘Gregory series’)
disp(‘pi=sum over k from 0 to inf of (4*((-1)^k/(2*k+1))’)
disp(‘  ‘)
disp(‘Ramanajun Series’)
disp(‘1/pi=sum over k from 0 to infinity of 2*sqrt(2)/9801*((4k)!*(1103+26390k)/(k!)^4*396^(4*k))’)

%% INPUTS.
%If you want to experiment this the only parameter
% you should and can change.
% Maximum number of terms
n=30;

%% PROGRAM

%% GREGORY SERIES
pi_gregory=0;
for i=1:1:n
pi_gregory=pi_gregory+(-1)^(i+1)*4*(1/(2*i-1));
pi_gregory_array(i)=pi_gregory;
end

%% RAMANUJAN SERIES
pi_ram=0;
for i=0:1:n-1
pi_ram=pi_ram+2*sqrt(2)/9801.0*(factorial(4*i))*(1103.0+26390.0*i)/((factorial(i)^4)*(396)^(4*i));
pi_ram_array(i+1)=1/pi_ram;
end

%% THE OUTPUT
disp(‘ ‘)
fprintf(‘\nNumber of Terms = %g’,n)
fprintf(‘\nGregory Series Value = %g’,pi_gregory)
fprintf(‘\nRamanujan Series Value = %g’,1/pi_ram)
disp( ‘   ‘)

%% PLOTTING THE TWO SERIES AS A FUNCTION OF TERMS
x=1:1:n;
hold on
xlabel(‘Number of terms’)
ylabel(‘Value of pi’)
title(‘Comparing Gregory and Ramanujan series’)
plot(x,pi_gregory_array,’color’,’blue’,’LineWidth’,2)
hold on
plot(x,pi_ram_array,’color’,’black’,’LineWidth’,2)
legend(‘Gregory Series’,’Ramanajun Series’,1)

This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at http://nm.mathforcollege.com.

An abridged (for low cost) book on Numerical Methods with Applications will be in print (includes problem sets, TOC, index) on December 10, 2008 and available at lulu storefront.

Subscribe to the blog via a reader or email to stay updated with this blog. Let the information follow you.

0 thoughts on “Comparing two series to calculate pi”

  1. The above iterative schemes show that the pi number can be generated by simple way using computer. But I believe the calculation of the pi number will be more easy when a simple analytical formulation of the magic number is available.

  2. The above iterative schemes show that the pi number can be generated by simple way using computer. But I believe the calculation of the pi number will be more easy when a simple analytical formulation of the magic number is available.

  3. Oh thanks, you are pleased me to give brief explanation about the simple analytical formulation for pi number.

    We know that until now there are so many formulas for pi number. The simpliest exact formula of pi is 4*arctan(1), where arctan(1)=1-1/3+1/5-1/7+1/9… But as discussed here, the primary drawback of the infinite series of 1-1/3+1/5-1/7+1/9…called as Gregory-Leibniz Series is too slowly to converg, that also shown on this link :

    http://www.eveandersson.com/pi/gregory-leibniz

    Actually, there is another exact formula or the pi number called Machin’s Formula

    pi=16*arctan(1/5)-4*arctan(1/239)

    (Please search it via google). But, there is still problem because the formula contains the arctan function.

    Recently, creating the pi number until more than million digits has been performed using BBP Formula based on haxadecimal coding , please visit to this link for detail explanation,

    http://en.wikipedia.org/wiki/Bailey-Borwein-Plouffe_formula

    But, as explained at this link :

    http://mathworld.wolfram.com/PiFormulas.html

    the BBP formula was created by complicated function, and also we can’t use the formula easily.

    Apologise, as I posted on http://eqworld.ipmnet.ru/forum/viewtopic.php?f=2&t=34&start=30, after a week from the last Pi Day (3/14/09) I found a simple analytic exact formula for pi number that now in preparing to be published. By using my formula, the pi number can be created by hand easily. I hope Professor Autar Kaw can inform me appropriate math journal to publish my exact pi formula.

    Best Regards.
    Rohedi.

  4. Oh thanks, you are pleased me to give brief explanation about the simple analytical formulation for pi number.

    We know that until now there are so many formulas for pi number. The simpliest exact formula of pi is 4*arctan(1), where arctan(1)=1-1/3+1/5-1/7+1/9… But as discussed here, the primary drawback of the infinite series of 1-1/3+1/5-1/7+1/9…called as Gregory-Leibniz Series is too slowly to converg, that also shown on this link :

    http://www.eveandersson.com/pi/gregory-leibniz

    Actually, there is another exact formula or the pi number called Machin’s Formula

    pi=16*arctan(1/5)-4*arctan(1/239)

    (Please search it via google). But, there is still problem because the formula contains the arctan function.

    Recently, creating the pi number until more than million digits has been performed using BBP Formula based on haxadecimal coding , please visit to this link for detail explanation,

    http://en.wikipedia.org/wiki/Bailey-Borwein-Plouffe_formula

    But, as explained at this link :

    http://mathworld.wolfram.com/PiFormulas.html

    the BBP formula was created by complicated function, and also we can’t use the formula easily.

    Apologise, as I posted on http://eqworld.ipmnet.ru/forum/viewtopic.php?f=2&t=34&start=30, after a week from the last Pi Day (3/14/09) I found a simple analytic exact formula for pi number that now in preparing to be published. By using my formula, the pi number can be created by hand easily. I hope Professor Autar Kaw can inform me appropriate math journal to publish my exact pi formula.

    Best Regards.
    Rohedi.

  5. Oh thanks, you are please me to give brief explanation about the simple analytical formulation for pi number.

    We know that until now there are so many formulas for pi number. The simpliest exact formula of pi is 4*arctan(1), where arctan(1)=1-1/3+1/5-1/7+1/9… But as discussed here, the primary drawback of the infinite series of 1-1/3+1/5-1/7+1/9…called as Gregory-Leibniz Series is too slowly to converg, that also shown on this link :

    http://www.eveandersson.com/pi/gregory-leibniz

    Actually, there is another exact formula or the pi number called Machin’s Formula

    pi=16*arctan(1/5)-4*arctan(1/239)

    (Please search it via google). But, there is still problem because the formula contains the arctan function.

    Recently, creating the pi number until more than million digits has been performed using BBP Formula based on haxadecimal coding , please visit to this link for detail explanation,

    http://en.wikipedia.org/wiki/Bailey-Borwein-Plouffe_formula

    But, as explained at this link :

    http://mathworld.wolfram.com/PiFormulas.html

    the BBP formula was created by complicated function, and also we can’t use the formula easily.

    Apologise, as I post on http://eqworld.ipmnet.ru/forum/viewtopic.php?f=2&t=34&start=30, after a week from the last Pi Day (3/14/09) I found a simple analytic exact formula for pi number that now in preparing to be published. By using my formula, the pi number can be created by hand easily. I hope Professor Autar Kaw can inform me appropriate math journal to publish my exact pi formula.

    Best Regards.
    Rohedi.

  6. Oh thanks, you are please me to give brief explanation about the simple analytical formulation for pi number.

    We know that until now there are so many formulas for pi number. The simpliest exact formula of pi is 4*arctan(1), where arctan(1)=1-1/3+1/5-1/7+1/9… But as discussed here, the primary drawback of the infinite series of 1-1/3+1/5-1/7+1/9…called as Gregory-Leibniz Series is too slowly to converg, that also shown on this link :

    http://www.eveandersson.com/pi/gregory-leibniz

    Actually, there is another exact formula or the pi number called Machin’s Formula

    pi=16*arctan(1/5)-4*arctan(1/239)

    (Please search it via google). But, there is still problem because the formula contains the arctan function.

    Recently, creating the pi number until more than million digits has been performed using BBP Formula based on haxadecimal coding , please visit to this link for detail explanation,

    http://en.wikipedia.org/wiki/Bailey-Borwein-Plouffe_formula

    But, as explained at this link :

    http://mathworld.wolfram.com/PiFormulas.html

    the BBP formula was created by complicated function, and also we can’t use the formula easily.

    Apologise, as I post on http://eqworld.ipmnet.ru/forum/viewtopic.php?f=2&t=34&start=30, after a week from the last Pi Day (3/14/09) I found a simple analytic exact formula for pi number that now in preparing to be published. By using my formula, the pi number can be created by hand easily. I hope Professor Autar Kaw can inform me appropriate math journal to publish my exact pi formula.

    Best Regards.
    Rohedi.

  7. Dear Prof.Autar Kaw,

    Now, Rohedi gives special comment for the fact that 0.999… = 1 as appear at the list of automatically generated, that recently it has discussed at so many math blogs, such as at

    http://ardoris.wordpress.com/2009/03/29/0999-1/

    and

    http://math152.wordpress.com/2009/01/13/interesting-proof-by-contradiction/.

    They generally prove the above equality by using geometric series and proof by contradiction.

    But, Rohedi still doesn’t believe to the existence of

    0.999…=1,

    because ….

    Let add the both sides with pi/4,

    0.999… + pi/4= 1 + pi/4,

    Taking tangent function for both sides

    tan(0.999… + pi/4)= tan(1 + pi/4),

    we will find

    [tan(.999…)+1]/[1-tan(.999…)]= [tan(1)+1]/
    [1-tan(1)].

    Of course mathematicians has not a reason to say that

    tan(.999…)=tan(1)

    How about you??

    Best Regards,
    Rohedi (http://rohedi.com)

  8. Dear Prof.Autar Kaw,

    Now, Rohedi gives special comment for the fact that 0.999… = 1 as appear at the list of automatically generated, that recently it has discussed at so many math blogs, such as at

    http://ardoris.wordpress.com/2009/03/29/0999-1/

    and

    http://math152.wordpress.com/2009/01/13/interesting-proof-by-contradiction/.

    They generally prove the above equality by using geometric series and proof by contradiction.

    But, Rohedi still doesn’t believe to the existence of

    0.999…=1,

    because ….

    Let add the both sides with pi/4,

    0.999… + pi/4= 1 + pi/4,

    Taking tangent function for both sides

    tan(0.999… + pi/4)= tan(1 + pi/4),

    we will find

    [tan(.999…)+1]/[1-tan(.999…)]= [tan(1)+1]/
    [1-tan(1)].

    Of course mathematicians has not a reason to say that

    tan(.999…)=tan(1)

    How about you??

    Best Regards,
    Rohedi (http://rohedi.com)

  9. I often visit to eqworld.ipmnet.ru, the link for pi exact formula posted by Rohedi. But recently when visiting again the website gives message “no input file specified”. I need to copy contain of the post to be learned more. How I can find the article of pi formula and some related topics?

  10. I often visit to eqworld.ipmnet.ru, the link for pi exact formula posted by Rohedi. But recently when visiting again the website gives message “no input file specified”. I need to copy contain of the post to be learned more. How I can find the article of pi formula and some related topics?

  11. Yes, I met this website of numerical method guys when searching “pi number”, that was displayed by google at the third pages. And at the leave comment of this article I read some informations about Rohedi’s version of new pi exact formula. But, unfortunately, his posts has been deleted from the website of eqworld.ipmnet.ru/forum/ . Okay I try to contact Rohedi via contact us of his website rohedi.com, and I promise to back here gives further information from him. Thx Dr.Kaw.

  12. Yes, I met this website of numerical method guys when searching “pi number”, that was displayed by google at the third pages. And at the leave comment of this article I read some informations about Rohedi’s version of new pi exact formula. But, unfortunately, his posts has been deleted from the website of eqworld.ipmnet.ru/forum/ . Okay I try to contact Rohedi via contact us of his website rohedi.com, and I promise to back here gives further information from him. Thx Dr.Kaw.

  13. Yes, I met this website of numerical method guys when searching “pi number”, that was displayed by google at the third pages. And at the leave comment of this article I read some informations about Rohedi’s version of new pi exact formula. But, unfortunately, his posts has been deleted from the website of eqworld.ipmnet.ru/forum/ . Okay I try to contact Rohedi via contact us of his website rohedi.com, and I promise to back here for giving further information from him. Thx Dr.Kaw.

  14. Yes, I met this website of numerical method guys when searching “pi number”, that was displayed by google at the third pages. And at the leave comment of this article I read some informations about Rohedi’s version of new pi exact formula. But, unfortunately, his posts has been deleted from the website of eqworld.ipmnet.ru/forum/ . Okay I try to contact Rohedi via contact us of his website rohedi.com, and I promise to back here for giving further information from him. Thx Dr.Kaw.

Leave a Reply