圆周率π的几种计算方法与分析

How to calculate mathematics π π π(圆周率的计算方法)

From 翔文公益数学 © kumath@outlook.com

泰勒级数理论(Taylor’s theorem and Taylor series)

多项式逼近任意函数

多项式 (polynomial) 逼近 (approximate) 未知函数 f f f 在给定点附近的值,实际上就是找到多项式的系数 (coefficients): a 0 , a 1 , ⋯   , a n a_0, a_1, \cdots, a_n a0​,a1​,⋯,an​

P n ( x ) = a 0 + a 1 ( x − a ) + a 2 ( x − a ) 2 + ⋯ + a n ( x − a ) n + R ( ( x − a ) n + 1 ) P_n(x)=a_0+a_1(x-a)+a_2(x-a)^2+\cdots+a_n(x-a)^n+R((x-a)^{n+1}) Pn​(x)=a0​+a1​(x−a)+a2​(x−a)2+⋯+an​(x−a)n+R((x−a)n+1)

靠近给定点 x = a x=a x=a 逼近函数 f ( x ) f(x) f(x), 此处假定 (assuming) 函数 f ( x ) f(x) f(x) 在 x = a x = a x=a 有 n n n 阶微分(differentiable). 从而有 f ( x ) ≈ P n ( x ) f(x)\approx P_n(x) f(x)≈Pn​(x), 下面试着找出系数 a n , n = 0 , 1 , 2 , ⋯   , n a_n, n=0,1,2,\cdots,n an​,n=0,1,2,⋯,n.

泰勒级数(Taylor series) 实函数或复函数(a real or complex-valued function) f ( x ) f(x) f(x) 在 x = a x=a x=a 有无限阶微分,则可以表示为幂级数 (power series):

f ( x ) ≈ f ( a ) + f ′ ( a ) 1 ! ( x − a ) + f ′ ′ ( a ) 2 ! ( x − a ) 2 + f ′ ′ ′ ( a ) 3 ! ( x − a ) 3 + ⋯ f(x) \approx \displaystyle f(a)+{\frac {f'(a)}{1!}}(x-a)+{\frac {f''(a)}{2!}}(x-a)^{2}+{\frac {f'''(a)}{3!}}(x-a)^{3}+\cdots f(x)≈f(a)+1!f′(a)​(x−a)+2!f′′(a)​(x−a)2+3!f′′′(a)​(x−a)3+⋯

此处 n ! n! n! 表示 n n n的阶乘 (denotes the factorial), f ( n ) ( a ) f^{(n)}(a) f(n)(a) 表示 f f f 在 x = a x=a x=a 处的 n n n 阶微分 (derivative). 可以写成更加紧凑的求和式子:

泰勒级数 f ( x ) = ∑ n = 0 ∞ f ( n ) ( a ) n ! ( x − a ) n . f(x)={\displaystyle \sum _{n=0}^{\infty }{\frac {f^{(n)}(a)}{n!}}(x-a)^{n}.} f(x)=n=0∑∞​n!f(n)(a)​(x−a)n.

f f f 的0阶导数就是它自己 f f f,且 ( x − a ) 0 = 0 ! = 1 (x − a)^0 = 0!=1 (x−a)0=0!=1. 当 a = 0 a = 0 a=0, 此时的泰勒级数又叫做 麦克劳林级数 Maclaurin series.

举例 (For instance)

指数函数(exponential function)
指数函数是重要的基本初等函数之一。一般地, y = a x y=a^x y=ax 函数 ( a (a (a 为常数且 a > 0 , a ≠ 1 ) a>0,a≠1) a>0,a​=1) 叫做 指数函数,函数的定义域是 x ∈ R x \in \mathbb{R} x∈R; 值域 (Domain)    ( 0 , + ∞ ) \text{(Domain)}\;(0,+\infty) (Domain)(0,+∞); 单调递增: a > 1 a>1 a>1 时, 单调递减: 0 < a < 1 0 < a < 1 0<a<1 时。 注意,在指数函数的定义表达式中,在 a x a^x ax 前的系数必须是数1,

指数函数应用到值 e e e 上的这个函数写为 exp ⁡ ( x ) \exp(x) exp(x)。还可以等价的写为 e x e^x ex,这里的 e e e 是数学常数,就是自然对数的底数,近似等于 2.718281828 2.718281828 2.718281828,还称为欧拉数.

作为实数变量 x x x 的函数, e x e^x ex 的图像总是正的(在 x x x 轴之上)并递增(从左向右看)。它永不触及 x x x 轴,尽管它可以无限程度地靠近 x x x 轴(所以, x x x 轴是这个图像的水平渐近线。它的反函数是 自然对数 ln ⁡ ( x ) \ln(x) ln(x),它定义在所有正数 x x x 上。

指数函数 e x e^x ex 在 a = 0 a = 0 a=0 处的泰勒级数展开式为:

∑ n = 0 ∞ x n n ! = x 0 0 ! + x 1 1 ! + x 2 2 ! + x 3 3 ! + x 4 4 ! + x 5 5 ! + ⋯ = 1 + x + x 2 2 + x 3 6 + x 4 24 + x 5 120 + ⋯ \displaystyle \begin{aligned}\sum _{n=0}^{\infty }{\frac {x^{n}}{n!}}& = {\frac {x^{0}}{0!}}+{\frac {x^{1}}{1!}}+{\frac {x^{2}}{2!}}+{\frac {x^{3}}{3!}}+{\frac {x^{4}}{4!}}+{\frac {x^{5}}{5!}}+\cdots \\& = 1+x+{\frac {x^{2}}{2}}+{\frac {x^{3}}{6}}+{\frac {x^{4}}{24}}+{\frac {x^{5}}{120}}+\cdots \end{aligned} n=0∑∞​n!xn​​=0!x0​+1!x1​+2!x2​+3!x3​+4!x4​+5!x5​+⋯=1+x+2x2​+6x3​+24x4​+120x5​+⋯​

e x e^x ex 对 x x x 求导,始终不变,还是 e x e^x ex,且 e 0 = 1 e^0=1 e0=1. 剩下的分子 (numerator) 为 ( x − 0 ) n (x − 0)^n (x−0)n, 分母 (denominator) 为 n ! n! n!.

绝妙公式 (Euler formula): e i x = cos ⁡ ( x ) + i    sin ⁡ ( x ) e^{ix}=\cos(x)+\text{i}\; \sin(x) eix=cos(x)+isin(x)

指数函数 e z e^z ez at z = 0 z=0 z=0 的泰勒级数展开式为

e z = ∑ n = 0 ∞ z n n ! = z 0 0 ! + z 1 1 ! + z 2 2 ! + z 3 3 ! + z 4 4 ! + z 5 5 ! + ⋯ = 1 + z + z 2 2 + z 3 6 + z 4 24 + z 5 120 + ⋯ \displaystyle \begin{aligned}e^z&=\sum _{n=0}^{\infty }{\frac {z^{n}}{n!}}\\&={\frac {z^{0}}{0!}}+{\frac {z^{1}}{1!}}+{\frac {z^{2}}{2!}}+{\frac {z^{3}}{3!}}+{\frac {z^{4}}{4!}}+{\frac {z^{5}}{5!}}+\cdots \\&=1+z+{\frac {z^{2}}{2}}+{\frac {z^{3}}{6}}+{\frac {z^{4}}{24}}+{\frac {z^{5}}{120}}+\cdots \end{aligned} ez​=n=0∑∞​n!zn​=0!z0​+1!z1​+2!z2​+3!z3​+4!z4​+5!z5​+⋯=1+z+2z2​+6z3​+24z4​+120z5​+⋯​

令 z = i x z=ix z=ix(纯虚数), 此处 i i i 虚数单位(imaginary unit), 满足 i 4 k = 1 , i 4 k + 1 = i , i 4 k + 2 = − 1 , i 4 k + 3 = − i i^{4k}=1, i^{4k+1}=i, i^{4k+2}=-1, i^{4k+3}=-i i4k=1,i4k+1=i,i4k+2=−1,i4k+3=−i.

左边为 e i x = cos ⁡ ( x ) + i    sin ⁡ ( x ) \large\red {e^{ix}=\cos(x)+i\;\sin(x)} eix=cos(x)+isin(x)
右边为 1 + i x − x 2 2 ! − i x 3 3 ! + x 4 4 ! + i x 5 5 ! − x 6 6 ! − i x 7 7 ! + ⋯ {\displaystyle {\begin{aligned} 1+ix-\frac{x^2}{2!}-i \frac{x^3}{3!}+\frac{x^4}{4!}+i \frac{x^5}{5!}-\frac{x^6}{6!}-i \frac{x^7}{7!}+\cdots \end{aligned}}} 1+ix−2!x2​−i3!x3​+4!x4​+i5!x5​−6!x6​−i7!x7​+⋯​

所以

cos ⁡ ( x ) = 1 − x 2 2 ! + x 4 4 ! − x 6 6 ! + ⋯ ( 偶 函 数 ) sin ⁡ ( x ) = x − x 3 3 ! + x 5 5 ! − x 7 7 ! + ⋯ ( 奇 函 数 ) \displaystyle \red{\cos(x)} = 1-\frac{x^2}{2!}+\frac{x^4}{4!}-\frac{x^6}{6!}+\cdots (偶函数)\\[1em] \red{\sin(x)} = x-\frac{x^3}{3!}+\frac{x^5}{5!}-\frac{x^7}{7!}+\cdots (奇函数) cos(x)=1−2!x2​+4!x4​−6!x6​+⋯(偶函数)sin(x)=x−3!x3​+5!x5​−7!x7​+⋯(奇函数)

上面也是函数 cos ⁡ ( x ) \cos(x) cos(x) sin ⁡ ( x ) \sin(x) sin(x) 的泰勒级数展开式. (请参照 Colin Maclaurin series, ∀ x \forall x ∀x)

写成紧凑的求和式为:
cos ⁡ ( x ) = ∑ n = 0 ∞ ( − 1 ) n x 2 n ( 2 n ) ! = 1 − x 2 2 ! + x 4 4 ! − x 6 6 ! + ⋯   . \displaystyle \begin{aligned}\cos(x)&=\sum _{n=0}^{\infty }{\frac {(-1)^nx^{2n}}{(2n)!}}\\&={1}-{\frac {x^{2}}{2!}}+{\frac {x^{4}}{4!}}-{\frac {x^{6}}{6!}}+\cdots .\end{aligned} cos(x)​=n=0∑∞​(2n)!(−1)nx2n​=1−2!x2​+4!x4​−6!x6​+⋯.​

sin ⁡ ( x ) = ∑ n = 0 ∞ ( − 1 ) n x 2 n + 1 ( 2 n + 1 ) ! = x − x 3 3 ! + x 5 5 ! − x 7 7 ! + ⋯   . \displaystyle \begin{aligned}\sin(x)&=\sum _{n=0}^{\infty }{\frac {(-1)^nx^{2n+1}}{(2n+1)!}}\\&={x}-{\frac {x^{3}}{3!}}+{\frac {x^{5}}{5!}}-{\frac {x^{7}}{7!}}+\cdots .\end{aligned} sin(x)​=n=0∑∞​(2n+1)!(−1)nx2n+1​=x−3!x3​+5!x5​−7!x7​+⋯.​

可见, cos ⁡ ( x ) \cos(x) cos(x) 是偶函数, sin ⁡ ( x ) \sin(x) sin(x) 是奇函数

显然,我们也可以通过泰勒展开得到上述式子。多阶导数有下列规律:

sin ⁡ ( 2 k ) ( x ) = d ( 2 k ) sin ⁡ ( x ) d x = ( − 1 ) k sin ⁡ ( x ) sin ⁡ ( 2 k + 1 ) ( x ) = ( − 1 ) k cos ⁡ ( x ) \sin^{(2k)}(x)= \frac{d^{(2k)}\sin(x)}{dx}=(-1)^k \sin(x)\\[1em] \sin^{(2k+1)}(x)=(-1)^k \cos(x) sin(2k)(x)=dxd(2k)sin(x)​=(−1)ksin(x)sin(2k+1)(x)=(−1)kcos(x)

sin ⁡ ( x ) \sin(x) sin(x) 在 x = 0 x=0 x=0 处的偶次导数为 0, sin ⁡ ( x ) \sin(x) sin(x) 在 x = 0 x=0 x=0 奇次导数为 ( − 1 ) k (-1)^k (−1)k

多项式逼近理论 (Polynomial approximation theorem)

问题: 求方程 sin ⁡ ( x ) = 0 \sin(x)=0 sin(x)=0 的解。

  1. 首先, sin ⁡ ( x ) = 0 \sin(x)=0 sin(x)=0 有解 { k π , k = 0 , ± 1 , ± 2 , ⋯   . } \{kπ,k=0,\pm 1,\pm 2, \cdots .\} {kπ,k=0,±1,±2,⋯.}

  2. According to , 假设 sin ⁡ ( x ) \sin(x) sin(x) 是多项式函数,由多项式有根的代数基本理论 (the fundamental theorem of algebra) 即 多项式逼近理论 (polynomial approximation theorem)

sin ⁡ ( x ) = c ∗ ∏ k = 1 ∞ ( k π − x ) ( k π + x ) x sin ⁡ ( x ) x = c ∗ ∏ k = 1 ∞ ( k π − x ) ( k π + x ) \displaystyle \sin(x) = c*\prod_{k=1}^{\infty} (kπ-x)(kπ+x)x \\[1em]\frac{\sin(x)}{x} = c*\prod_{k=1}^{\infty} (kπ-x)(kπ+x) sin(x)=c∗k=1∏∞​(kπ−x)(kπ+x)xxsin(x)​=c∗k=1∏∞​(kπ−x)(kπ+x)

令 x → 0 x \to 0 x→0, 求极限得到
c = ∏ k = 1 ∞ 1 k 2 π 2 \displaystyle c=\prod_{k=1}^{\infty} \frac {1}{k^2π^2} c=k=1∏∞​k2π21​

我们得到:

sin ⁡ ( x ) = x ∏ k = 1 ∞ ( 1 − x k π ) ( 1 + x k π ) = x ∏ k = 1 ∞ [ 1 − x 2 ( k π ) 2 ] \displaystyle \begin{aligned} \sin(x) &= x {\prod_{k=1} ^{\infty} ({1- \frac{x}{kπ})} (1+ \frac{x}{kπ})} \\&= x \prod_{k=1} ^{\infty} \left[1- \frac{x^2}{(kπ)^2}\right ] \end{aligned} sin(x)​=xk=1∏∞​(1−kπx​)(1+kπx​)=xk=1∏∞​[1−(kπ)2x2​]​

令 x = π 2 x = \frac{π}{2} x=2π​, 有

π 2 = ∏ k = 1 ∞ 2 k 2 k − 1 ⋅ 2 k 2 k + 1 = ∏ k = 1 ∞ 1 1 − 1 4 k 2 = 2 1 ⋅ 2 3 ⋅ 4 3 ⋅ 4 5 ⋅ 6 5 ⋅ 6 7 ⋯ = 4 3 ⋅ 16 15 ⋅ 36 35 ⋅ 64 63 ⋯ \displaystyle \begin{aligned} \frac{π}{2} &= \prod_{k=1} ^{\infty} \frac{2k}{2k-1} \centerdot \frac{2k}{2k+1} \\&= \prod_{k=1} ^{\infty} \frac{1}{1- \frac{1}{4k^2}} \\&=\frac{2}{1} \centerdot \frac{2}{3} \centerdot \frac{4}{3} \centerdot \frac{4}{5} \centerdot \frac{6}{5} \centerdot \frac{6}{7} \cdots \\&=\frac{4}{3} \centerdot \frac{16}{15} \centerdot \frac{36}{35} \centerdot \frac{64}{63} \cdots \end{aligned} 2π​​=k=1∏∞​2k−12k​⋅2k+12k​=k=1∏∞​1−4k21​1​=12​⋅32​⋅34​⋅54​⋅56​⋅76​⋯=34​⋅1516​⋅3536​⋅6364​⋯​

参见 John Wallis’ product for π π π

同理可得

cos ⁡ ( x ) = ∏ k = 1 ∞ ( 1 − 2 x ( 2 k − 1 ) π ) ( 1 + 2 x ( 2 k − 1 ) π ) = x ∏ k = 1 ∞ ( 1 − 4 x 2 ( 2 k − 1 ) 2 π 2 ) \displaystyle \begin{aligned}\cos(x)&=\prod_{k=1} ^{\infty} {(1 - \frac{2x}{(2k-1)π})} {(1 + \frac{2x}{(2k-1)π})}\\&=x \prod_{k=1} ^{\infty} {(1-\frac{4x^2}{(2k-1)^2 π^2})} \end{aligned} cos(x)​=k=1∏∞​(1−(2k−1)π2x​)(1+(2k−1)π2x​)=xk=1∏∞​(1−(2k−1)2π24x2​)​

tan ⁡ ( x ) = x π 4 ⋅ ∏ k = 1 ∞ 1 − x k π 1 − 1 4 k ⋅ 1 + x k π 1 + 1 4 k \displaystyle \begin{aligned} \tan(x)&=\frac{x}{\frac{\pi}{4}} \centerdot \prod_{k=1} ^{\infty} \frac{1 - \frac{x}{kπ}}{1-\frac{1}{4k}} \centerdot \frac{1 + \frac{x}{kπ}}{1+\frac{1}{4k}}\end{aligned} tan(x)​=4π​x​⋅k=1∏∞​1−4k1​1−kπx​​⋅1+4k1​1+kπx​​​

欧拉恒等式 (Euler identity)

  1. 泰勒展开理论得到
    sin ⁡ ( x ) = x − x 3 3 ! + x 5 5 ! + ⋯ \displaystyle \begin{aligned} \sin(x)&=x-\frac{x^3}{3!}+\frac{x^5}{5!}+\cdots \end{aligned} sin(x)​=x−3!x3​+5!x5​+⋯​

  2. 多项式逼近理论得到
    sin ⁡ ( x ) = x ∏ k = 1 ∞ ( 1 − x 2 ( k π ) 2 ) \displaystyle \begin{aligned} \sin(x)&= x \prod_{k=1} ^{\infty} (1- \frac{x^2}{(kπ)^2}) \end{aligned} sin(x)​=xk=1∏∞​(1−(kπ)2x2​)​

  3. 比较 x 3 x^3 x3 的系数可得
    1 3 ! = ∑ k = 1 ∞ 1 ( k π ) 2 \displaystyle {\begin{aligned} \frac{1}{3!}&= \sum_{k=1} ^{\infty} \frac{1}{(kπ)^2} \end{aligned}} 3!1​​=k=1∑∞​(kπ)21​​

    所以
    π 2 6 = ∑ k = 1 ∞ 1 k 2 = 1 + 1 4 + 1 9 + ⋯ + 1 n 2 + ⋯ \displaystyle \begin{aligned} \frac{π^2}{6}&=\sum_{k=1} ^{\infty} \frac{1}{k^2}\\&=1+\frac{1}{4}+\frac{1}{9}+\cdots + \frac{1}{n^2}+\cdots \end{aligned} 6π2​​=k=1∑∞​k21​=1+41​+91​+⋯+n21​+⋯​
    收敛速度还可以接受。

    from sympy import summation
    k = Symbol('k',integer=True)
    summation(1/k**2,(k,1,oo))
    

    计算 π = 6 ∑ k = 1 ∞ 1 k 2 \pi=\sqrt{6 \displaystyle \sum_{k=1}^{\infty}\dfrac{1}{k^2}} π=6k=1∑∞​k21​

Gregory-Leibniz series

格雷戈里-莱布尼茨级数于 1671年2月15日提出。

反正切函数的级数 (series for the inverse tangent function), 也称为 Gregory’s series:
arctan ⁡ ( x ) = x − x 3 3 + x 5 5 − x 7 7 + ⋯ = ∑ k = 0 ∞ ( − 1 ) k x 2 k + 1 2 k + 1 \displaystyle \begin{aligned} \arctan(x)&=x-\dfrac{x^3}{3}+\dfrac{x^5}{5}-\dfrac{x^7}{7}+\cdots\\&=\sum_{k=0}^\infty(-1)^k\dfrac{x^{2k+1}}{2k+1} \end{aligned} arctan(x)​=x−3x3​+5x5​−7x7​+⋯=k=0∑∞​(−1)k2k+1x2k+1​​

推导过程如下:
∵ d ( arctan ⁡ x ) d x = 1 1 + x 2 \because \dfrac{d(\arctan x)}{dx}=\dfrac{1}{1+x^2} ∵dxd(arctanx)​=1+x21​
∵ 1 − x n = ( 1 − x ) ( 1 + x + x 2 + ⋯ + x n − 1 ) ∴ 1 1 − x = ∑ n = 0 ∞ x n ,    ∣ x ∣ < 1 \because 1-x^n=(1-x)(1+x+x^2+\cdots+x^{n-1})\\\therefore \dfrac{1}{1-x}=\displaystyle\sum_{n=0}^{\infty} x^n,\;|x|<1 ∵1−xn=(1−x)(1+x+x2+⋯+xn−1)∴1−x1​=n=0∑∞​xn,∣x∣<1
1 1 + x 2 = 1 1 − ( − x 2 ) = ∑ n = 0 ∞ ( − x 2 ) n = ∑ n = 0 ∞ ( − 1 ) n x 2 n \dfrac{1}{1+x^2}=\dfrac{1}{1-(-x^2)}=\displaystyle\sum_{n=0}^{\infty}(-x^2)^n=\sum_{n=0}^{\infty}(-1)^nx^{2n} 1+x21​=1−(−x2)1​=n=0∑∞​(−x2)n=n=0∑∞​(−1)nx2n

∴ arctan ⁡ ( x ) = ∫ 1 1 + x 2 d x = ∫ ∑ n = 0 ∞ ( − 1 ) n x 2 n d x = ∑ n = 0 ∞ ( − 1 ) n x 2 n + 1 2 n + 1 ,    ∣ x ∣ < 1 \begin{aligned} \therefore \arctan(x)&=\int\dfrac{1}{1+x^2}\mathrm{d}x\\ &=\displaystyle\int\sum_{n=0}^{\infty}(-1)^nx^{2n}\mathrm{d}x\\ &=\sum_{n=0}^{\infty}(-1)^n\dfrac{x^{2n+1}}{2n+1}, \;|x|<1 \end{aligned} ∴arctan(x)​=∫1+x21​dx=∫n=0∑∞​(−1)nx2ndx=n=0∑∞​(−1)n2n+1x2n+1​,∣x∣<1​

莱布尼茨公式 (Leibniz formula) π 4 \dfrac{π}{4} 4π​ 可以通过 x = 1 x = 1 x=1 ( T O D O ? ) \red{(TODO?)} (TODO?) 代入上述反正切函数的级数中得到.这里有一个疑问,既然 要求 ∣ x ∣ < 1 |x|<1 ∣x∣<1, 又怎么能取 x = 1 x=1 x=1 呢?

π 4 = ∑ n = 0 ∞ ( − 1 ) n 2 n + 1 = 1 1 − 1 3 + 1 5 − 1 7 + ⋯   . \displaystyle \frac{\pi}{4} = \sum_{n=0}^{\infty}\frac{(-1)^n}{2n+1} = \frac{1}{1}- \frac{1}{3}+ \frac{1}{5}- \frac{1}{7}+ \cdots. 4π​=n=0∑∞​2n+1(−1)n​=11​−31​+51​−71​+⋯.

正如你看到,这个级数的收敛极慢!不可取

Nilakantha Series

π = 3 + 4 2 ⋅ 3 ⋅ 4 − 4 4 ⋅ 5 ⋅ 6 + 4 6 ⋅ 7 ⋅ 8 − 4 8 ⋅ 9 ⋅ 10 + ⋯ = 3 + 1 1 ⋅ 3 ⋅ 2 − 1 2 ⋅ 5 ⋅ 3 + 1 3 ⋅ 7 ⋅ 4 − 1 4 ⋅ 9 ⋅ 5 + ⋯ = 3 + ∑ n = 2 ∞ ( − 1 ) n ( n − 1 ) n ( 2 n − 1 ) \displaystyle \begin{aligned} {\pi} &= 3+ \frac{4}{2 \centerdot 3 \centerdot 4}- \frac{4}{4 \centerdot 5 \centerdot 6}+ \frac{4}{6 \centerdot 7 \centerdot 8}- \frac{4}{8 \centerdot 9 \centerdot 10}+ \cdots \\&= 3+ \frac{1}{1 \centerdot 3 \centerdot 2}- \frac{1}{2 \centerdot 5 \centerdot 3}+ \frac{1}{3 \centerdot 7 \centerdot 4}- \frac{1}{4 \centerdot 9 \centerdot 5}+ \cdots \\&= 3+ \sum_{n=2}^{\infty} \frac{(-1)^n}{(n-1)n(2n-1)} \end{aligned} π​=3+2⋅3⋅44​−4⋅5⋅64​+6⋅7⋅84​−8⋅9⋅104​+⋯=3+1⋅3⋅21​−2⋅5⋅31​+3⋅7⋅41​−4⋅9⋅51​+⋯=3+n=2∑∞​(n−1)n(2n−1)(−1)n​​

This is the faster convergent method for pi.
这是计算圆周率的更快一点的收敛方法。

Viete’s Formula

Viète’s formula is the following infinite product of nested radicals representing the mathematical constant π π π:
2 π = 2 2 ⋅ 2 + 2 2 ⋅ 2 + 2 + 2 2 ⋯ \displaystyle {\frac {2}{\pi }}={\frac {\sqrt {2}}{2}}\cdot {\frac {\sqrt {2+{\sqrt {2}}}}{2}}\cdot {\frac {\sqrt {2+{\sqrt {2+{\sqrt {2}}}}}}{2}}\cdots π2​=22 ​​⋅22+2 ​​⋅22+2+2 ​​⋯
It is named after François Viète (1540–1603), who published it in 1593.

Viète’s formula may be rewritten and understood as a limit expression.
lim ⁡ n → ∞ ∏ i = 1 n a i 2 = 2 π \displaystyle \lim _{n\rightarrow \infty }\prod _{i=1}^{n}{\frac {a_{i}}{2}}={\frac {2}{\pi }} n→∞lim​i=1∏n​2ai​​=π2​
where a n = 2 + a n − 1 a_n = \sqrt{2 + a_{n − 1}} an​=2+an−1​ ​, with initial condition a 1 = 2 a_1 = \sqrt{2} a1​=2 ​.

Viète’s formula may be obtained as a special case of a formula given more than a century later by Leonhard Euler, who discovered that:

sin ⁡ x x = cos ⁡ x 2 ⋅ cos ⁡ x 4 ⋅ cos ⁡ x 8 ⋯ {\displaystyle {\frac {\sin x}{x}}=\cos {\frac {x}{2}}\cdot \cos {\frac {x}{4}}\cdot \cos {\frac {x}{8}}\cdots } xsinx​=cos2x​⋅cos4x​⋅cos8x​⋯

Substituting
x = π 2 {\displaystyle x={\frac {\pi }{2}}} x=2π​ in this formula yields:

2 π = cos ⁡ π 4 ⋅ cos ⁡ π 8 ⋅ cos ⁡ π 16 ⋯ {\displaystyle {\frac {2}{\pi }}=\cos {\frac {\pi }{4}}\cdot \cos {\frac {\pi }{8}}\cdot \cos {\frac {\pi }{16}}\cdots} π2​=cos4π​⋅cos8π​⋅cos16π​⋯

Then, expressing each term of the product on the right as a function of earlier terms using the half-angle formula:

cos ⁡ x 2 = 1 + cos ⁡ x 2 {\displaystyle \cos {\frac {x}{2}}={\sqrt {\frac {1+\cos x}{2}}}} cos2x​=21+cosx​

gives Viète’s formula.

It is also possible to derive from Viète’s formula a related formula for π π π that still involves nested square roots of two, but uses only one multiplication: ref Viete formula

π = lim ⁡ k → ∞ 2 k 2 − 2 + 2 + 2 + 2 + ⋯ + 2 ⏟ k   s q u a r e    r o o t s \displaystyle \pi =\lim _{k\to \infty }2^{k}\underbrace {\sqrt {2-{\sqrt {2+{\sqrt {2+{\sqrt {2+{\sqrt {2+\cdots +{\sqrt {2}}}}}}}}}}}} _{k\ \mathrm {square \;roots}} π=k→∞lim​2kk squareroots 2−2+2+2+2+⋯+2 ​​​

反三角函数 arcsin ⁡ ( x ) \arcsin(x) arcsin(x)

1676年,牛顿给出的方法。令下列 x = 1 2 x=\dfrac{1}{2} x=21​
$\dfrac{d}{dx}(\sin{-1}x)=\dfrac{1}{\sqrt{1-x2}}\implies \$

sin ⁡ − 1 x = ∫ ( 1 − x 2 ) − 1 / 2 d x + c ( c o n s t a n t ) = ∫ ( 1 + x 2 2 + 3 x 4 8 + 5 x 6 16 + ⋯ + c ) ,    ∣ x ∣ < 1 = x + 1 2 x 3 3 + 1 ⋅ 3 2 ⋅ 4 x 5 5 + 1 ⋅ 3 ⋅ 5 2 ⋅ 4 ⋅ 6 x 7 7 + ⋯ + c \begin{aligned} \displaystyle \sin^{-1}x &=\int(1-x^2)^{-1/2}\mathrm{d}x+c(constant)\\ &=\int(1+\dfrac{x^2}{2}+\dfrac{3x^4}{8}+\dfrac{5x^6}{16}+\cdots+c),\;|x|<1\\ &=x+\dfrac{1}{2}\dfrac{x^3}{3}+\dfrac{1\cdot3}{2\cdot4}\dfrac{x^5}{5}+\dfrac{1\cdot3\cdot5}{2\cdot4\cdot6}\dfrac{x^7}{7}+\cdots+c \end{aligned} sin−1x​=∫(1−x2)−1/2dx+c(constant)=∫(1+2x2​+83x4​+165x6​+⋯+c),∣x∣<1=x+21​3x3​+2⋅41⋅3​5x5​+2⋅4⋅61⋅3⋅5​7x7​+⋯+c​

$\because \sin^{-1}x=0; \text{at}; x=0\implies c=0\$

∴ sin ⁡ − 1 ( x ) = x + 1 2 x 3 3 + 1 ⋅ 3 2 ⋅ 4 x 5 5 + 1 ⋅ 3 ⋅ 5 2 ⋅ 4 ⋅ 6 x 7 7 + ⋯   ,    ∣ x ∣ < 1 = ∑ n = 0 ∞ ( 2 n ) ! 2 2 n ( n ! ) 2 ( 2 n + 1 ) x 2 n + 1 \therefore \sin^{-1}(x)=x+\dfrac{1}{2}\dfrac{x^3}{3}+\dfrac{1\cdot3}{2\cdot4}\dfrac{x^5}{5}+\dfrac{1\cdot3\cdot5}{2\cdot4\cdot6}\dfrac{x^7}{7}+\cdots,\;|x|<1\\ =\displaystyle \sum_{n=0}^{\infty}\dfrac{(2n)!}{2^{2n}(n!)^2(2n+1)}x^{2n+1} ∴sin−1(x)=x+21​3x3​+2⋅41⋅3​5x5​+2⋅4⋅61⋅3⋅5​7x7​+⋯,∣x∣<1=n=0∑∞​22n(n!)2(2n+1)(2n)!​x2n+1

同理可以得到
∴ cos ⁡ − 1 ( x ) = π 2 − ( x + 1 2 x 3 3 + 1 ⋅ 3 2 ⋅ 4 x 5 5 + 1 ⋅ 3 ⋅ 5 2 ⋅ 4 ⋅ 6 x 7 7 + ⋯   ) ,    ∣ x ∣ < 1 = π 2 − ∑ n = 0 ∞ ( 2 n ) ! 2 2 n ( n ! ) 2 ( 2 n + 1 ) x 2 n + 1 \therefore \cos^{-1}(x)=\dfrac{\pi}{2}-\left(x+\dfrac{1}{2}\dfrac{x^3}{3}+\dfrac{1\cdot3}{2\cdot4}\dfrac{x^5}{5}+\dfrac{1\cdot3\cdot5}{2\cdot4\cdot6}\dfrac{x^7}{7}+\cdots\right),\;|x|<1\\ =\displaystyle \dfrac{\pi}{2}-\sum_{n=0}^{\infty}\dfrac{(2n)!}{2^{2n}(n!)^2(2n+1)}x^{2n+1} ∴cos−1(x)=2π​−(x+21​3x3​+2⋅41⋅3​5x5​+2⋅4⋅61⋅3⋅5​7x7​+⋯),∣x∣<1=2π​−n=0∑∞​22n(n!)2(2n+1)(2n)!​x2n+1

Taylor级数和Maclaurin Series的实现

在GeoGebra中可以轻松实现多项式之和逼近各种函数。

  1. 先定义次数Order的滑条 n = s l i d e r ( 1 , 20 , 1 ) n=slider(1,20,1) n=slider(1,20,1)
  2. 再定义要逼近的函数,如 f ( x ) = arctan ⁡ ( x ) , g ( x ) = sin ⁡ ( x ) , h ( x ) = cos ⁡ ( x ) , ⋯ f(x)=\arctan(x),g(x)=\sin(x),h(x)=\cos(x),\cdots f(x)=arctan(x),g(x)=sin(x),h(x)=cos(x),⋯
  3. 调用函数 g = T a y l o r P o l i n o m i a l ( f , x ( A ) , n ) ,    A = ( 0 , 0 ) g=TaylorPolinomial(f,x(A),n),\;A=(0,0) g=TaylorPolinomial(f,x(A),n),A=(0,0)
  4. 调用函数 F o r m u l a T e x t ( g , t r u e , t r u e ) FormulaText(g, true, true) FormulaText(g,true,true) 可以显示级数

TaylorSeries的多项式逼近演示GGB

计算 π \pi π 收敛速度极快算法

代数和几何结合的方法。

采用刘徽割圆术,用正 n n n 边形逼近圆的方法,实现计算圆周率 π \pi π 的目的。

记 正 n n n 边形的边长为 L n L_n Ln​, 由正 n n n 边形产生的正 2 n 2n 2n 边形的边长为 L 2 n L_{2n} L2n​, 则如图可有
圆周率π的几种计算方法与分析
L n = A A ′ , L 2 n = A B L 2 n 2 = ( L n 2 ) 2 + ( 1 − O C ) 2 = 1 4 L n 2 + ( 1 − 1 − 1 4 L n 2 ) 2 = 2 − 2 1 − 1 4 L n 2 L 2 n = 2 − 4 − L n 2 L_n=AA',L_{2n}=AB\\ L_{2n}^2=(\dfrac{L_n}{2})^2+(1-OC)^2\\ =\dfrac{1}{4}L_n^2+\left(1-\sqrt{1-\dfrac{1}{4}L_n^2}\right)^2\\ =2-2\sqrt{1-\dfrac{1}{4}L_n^2}\\ L_{2n}=\sqrt{2-\sqrt{4-L_n^2}} Ln​=AA′,L2n​=ABL2n2​=(2Ln​​)2+(1−OC)2=41​Ln2​+(1−1−41​Ln2​ ​)2=2−21−41​Ln2​ ​L2n​=2−4−Ln2​

单位圆的半径 r = 1 r=1 r=1, 则有正 6 6 6 边形的边长 L 6 = 1 L_6=1 L6​=1, 利用迭代关系式可以快速求出 周长
C O = 2 π = lim ⁡ n → ∞ ( n × L n ) π = 1 2 × lim ⁡ n → ∞ ( n × L n ) \displaystyle C_{O}=2\pi=\lim_{n\to \infty} (n \times L_{n})\\ \pi=\dfrac{1}{2}\times \lim_{n\to \infin} (n \times L_{n}) CO​=2π=n→∞lim​(n×Ln​)π=21​×n→∞lim​(n×Ln​)

即圆周率就是半周长,上述算法收敛性很快!

在GeoGebra中实现

  1. 先建立迭代次数滑动条 n = s l i d e r ( 1 , 10 , 1 ) n=slider(1,10,1) n=slider(1,10,1)
  2. 再建立迭代函数 f ( x ) = s q r t ( 2 − s q r t ( 4 − x    x ) ) f(x)=sqrt(2 - sqrt(4 - x\; x)) f(x)=sqrt(2−sqrt(4−xx))
  3. 然后用GGB的迭代命令 v a l u e = I t e r a t i o n ( f , 1 , n ) → value = Iteration(f, 1, n)\to value=Iteration(f,1,n)→ L 2 n = 2 − 4 − L n × L n , L 6 = 1 L_{2n}=\sqrt{2-\sqrt{4-L_n\times L_n}},L_6=1 L2n​=2−4−Ln​×Ln​ ​,L6​=1,初始值取正6边形时的值1.
  4. 正 2 n 2n 2n 边形的半周长为 π = v a l u e × 6 × 2 n − 1 \pi=value\times6\times2^{n-1} π=value×6×2n−1

这一算法的收敛也极快,正多边形的边数以指数级增长。边数 = 6 × 2 n − 1 =6\times2^{n-1} =6×2n−1

Python程序得到的结果

Python 源码 参见迭代计算圆周率π的Python源码

采用符号运算得到前10个结论:

12sqrt(2 - sqrt(3))
24
sqrt(2 - sqrt(sqrt(3) + 2))
48sqrt(2 - sqrt(sqrt(sqrt(3) + 2) + 2))
96
sqrt(2 - sqrt(sqrt(sqrt(sqrt(3) + 2) + 2) + 2))
192sqrt(2 - sqrt(sqrt(sqrt(sqrt(sqrt(3) + 2) + 2) + 2) + 2))
384
sqrt(2 - sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(3) + 2) + 2) + 2) + 2) + 2))
768sqrt(2 - sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(3) + 2) + 2) + 2) + 2) + 2) + 2))
1536
sqrt(2 - sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(3) + 2) + 2) + 2) + 2) + 2) + 2) + 2))
3072sqrt(2 - sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(3) + 2) + 2) + 2) + 2) + 2) + 2) + 2) + 2))
6144
sqrt(2 - sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(3) + 2) + 2) + 2) + 2) + 2) + 2) + 2) + 2) + 2))

第151次 到 第159次的迭代结果:

3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825324499856
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825337712765
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825341015992
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825341841799
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342048251
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342099864
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342112767
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342115993
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342116799

第 160 次迭代结果,准确到小数点后 第96位:

3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117001

圆周率小数点后100位

14 15 92 65 35 89 79 32 38 46 26 43 38 32 79 50 28 84 19 71 69 39 93 75 10 58 20 97 49 44 59 23 07 81 64 06 28 62 08 99 86 28 03 48 25 34 21 17 06 79 。

上一篇:如何根据经纬度计算地面上某点在XYZ空间直角坐标系中的坐标


下一篇:不定积分在考研中的“钓鱼题”