拉马努金的圆周率计算公式

拉马努金的几个神仙公式。据说他的论文里一共发表了14条圆周率的计算公式,但目前只收集到十个。

1 π = 1 8 ∑ m = 0 ∞ ( 20 m + 3 ) ( − 1 ) m ( 4 m ) ! ( 4 2 ) 4 m ( m ! ) 4 1 π = 1 2 3 ∑ m = 0 ∞ ( 8 m + 1 ) ( 4 m ) ! ( 4 3 ) 4 m ( m ! ) 4 1 π = 3 16 ∑ m = 0 ∞ ( 28 m + 3 ) ( − 1 ) m ( 4 m ) ! ( 64 3 ) 2 m ( m ! ) 4 1 π = 2 2 9 ∑ m = 0 ∞ ( 10 m + 1 ) ( 4 m ) ! 1 2 4 m ( m ! ) 4 1 π = 1 72 ∑ m = 0 ∞ ( 260 m + 23 ) ( − 1 ) m ( 4 m ) ! ( 12 2 ) 4 m ( m ! ) 4 1 π = 3 3 49 ∑ m = 0 ∞ ( 40 m + 3 ) ( 4 m ) ! 2 8 4 m ( m ! ) 4 1 π = 1 18 11 ∑ m = 0 ∞ ( 280 m + 19 ) ( 4 m ) ! ( 12 11 ) 4 m ( m ! ) 4 1 π = 5 288 ∑ m = 0 ∞ ( 644 m + 41 ) ( − 1 ) m ( 4 m ) ! ( 1152 5 ) 2 m ( m ! ) 4 1 π = 2 8 4 2 ∑ m = 0 ∞ ( 21460 m + 1123 ) ( − 1 ) m ( 4 m ) ! ( 84 2 ) 4 m ( m ! ) 4 1 π = 2 2 9 9 2 ∑ m = 0 ∞ ( 26390 m + 1103 ) ( 4 m ) ! 39 6 4 m ( m ! ) 4 \begin{aligned} \frac{1}{\pi} &=\frac{1}{8} \sum^{\infty}_{m=0}(20m+3)\frac{(-1)^m(4m)!}{(4\sqrt{2})^{4m}(m!)^4} & \quad \frac{1}{\pi} &=\frac{1}{2\sqrt{3}} \sum^{\infty}_{m=0}(8m+1)\frac{(4m)!}{(4\sqrt{3})^{4m}(m!)^4} \\ \frac{1}{\pi} &=\frac{\sqrt3}{16} \sum^{\infty}_{m=0}(28m+3)\frac{(-1)^m(4m)!}{(64\sqrt{3})^{2m}(m!)^4} & \quad \frac{1}{\pi} &=\frac{2\sqrt{2}}{9} \sum^{\infty}_{m=0}(10m+1)\frac{(4m)!}{12^{4m}(m!)^4} \\ \frac{1}{\pi} &=\frac{1}{72} \sum^{\infty}_{m=0}(260m+23)\frac{(-1)^m(4m)!}{(12\sqrt{2})^{4m}(m!)^4} & \quad \frac{1}{\pi} &=\frac{3\sqrt3}{49} \sum^{\infty}_{m=0}(40m+3)\frac{(4m)!}{28^{4m}(m!)^4} \\ \frac{1}{\pi} &=\frac{1}{18\sqrt{11}} \sum^{\infty}_{m=0}(280m+19)\frac{(4m)!}{(12\sqrt{11})^{4m}(m!)^4} & \quad \frac{1}{\pi} &=\frac{\sqrt{5}}{288} \sum^{\infty}_{m=0}(644m+41)\frac{(-1)^m(4m)!}{(1152\sqrt{5})^{2m}(m!)^4} \\ \frac{1}{\pi} &=\frac{2}{84^2} \sum^{\infty}_{m=0}(21460m+1123)\frac{(-1)^m(4m)!}{(84\sqrt{2})^{4m}(m!)^4} & \quad \frac{1}{\pi} &=\frac{2\sqrt{2}}{99^2} \sum^{\infty}_{m=0}(26390m+1103)\frac{(4m)!}{396^{4m}(m!)^4} \end{aligned} π1π1π1π1π1=81m=0(20m+3)(42 )4m(m!)4(1)m(4m)!=163 m=0(28m+3)(643 )2m(m!)4(1)m(4m)!=721m=0(260m+23)(122 )4m(m!)4(1)m(4m)!=1811 1m=0(280m+19)(1211 )4m(m!)4(4m)!=8422m=0(21460m+1123)(842 )4m(m!)4(1)m(4m)!π1π1π1π1π1=23 1m=0(8m+1)(43 )4m(m!)4(4m)!=922 m=0(10m+1)124m(m!)4(4m)!=4933 m=0(40m+3)284m(m!)4(4m)!=2885 m=0(644m+41)(11525 )2m(m!)4(1)m(4m)!=99222 m=0(26390m+1103)3964m(m!)4(4m)!

1989年,大卫·丘德诺夫斯基和格雷高里·丘德诺夫斯基兄弟将拉马努金公式改良。
1 π = 12 ∑ m = 0 ∞ 545140134 m + 13591409 64032 0 3 m + 3 2 × ( − 1 ) m ( 6 m ) ! ( 3 m ) ! ( m ! ) 3 \frac{1}{\pi}=12\sum^{\infty}_{m=0} \frac{545140134m+13591409}{640320^{3m+\frac{3}{2}}} \times \frac{(-1)^m(6m)!}{(3m)!(m!)^3} π1=12m=06403203m+23545140134m+13591409×(3m)!(m!)3(1)m(6m)!

百度拉马努金公式,搜索结果是最后一条,所以公式改良应该也是针对最后一条

用代码验证第一条公式:
我这里循环写到了26。因为循环在26到43之间取值都一样,毕竟笔记本精度有限;当超过43时,程序运行出错,毕竟笔记本能力有限

import math

sum = 0
for m in range(26):
    x = (20*m+3)*((-1)**m)*math.factorial(4*m)
    y = ((4*math.sqrt(2))**(4*m))*(math.factorial(m))**4
    sum = sum + x/y

pi = 8/sum

# π = 3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510
print(pi)

print(math.pi)

'''
可以看到效果还是很不错的,起码比math库多一位,但真实值应该是2,准确度还差点。
3.1415926535897936
3.141592653589793
'''

改良公式:(改良还是有道理的,2到18取值一样,超过18,程序出错)

import math

sum = 0
for m in range(2):
    x = (545140134*m+13591409)*((-1)**m)*math.factorial(6*m)
    y = ((640320)**(3*m+1.5)) * (math.factorial(3*m)) * (math.factorial(m))**3
    sum = sum + x/y


pi = 1/(12*sum)

# π = 3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510
print(pi)

print(math.pi)


'''
3.1415926535897936
3.141592653589793
'''

写了个Java代码,发现效果并不理想,循环超过10,输出就为NaN。
以下Java代码输出结果为:3.1463949385904666。而同是循环10次的python结果为:3.141593404158244
除了Math函数自身会将数值部分丢失,最大的问题就是Java的数据类型限制了范围。

    public static void main(String[] args) {
     

        Double sum = 0.0;
        for (int m = 0; m < 10; m++) {
     
            Double x = (20*m+3)*(Math.pow(-1, m))*factorial(4*m);
            Double y = (Math.pow(4*Math.sqrt(2), 4*m))*power(factorial(m),4);
            sum += x/y;
        }

        Double pi = 8/sum;

        System.out.println(pi);

    }


    // 利用递归计算阶乘
    public static int factorial(int num){
     
        int sum = 1;
        if(num==1 || num==0){
     
            return 1;
        }else{
     
            sum=num * factorial(num-1);//运用递归计算
            return sum;
        }
    }

    // 计算次方
    public static int power(int num, int n){
     
        int pow = 1;
        for (int i = 0; i < n; i++) {
     
            pow *= num;
        }
        return pow;
    }

你可能感兴趣的:(线性代数,数学)