From 翔文公益数学 © kumath@outlook.com
圆周率
- 从代数上来讲,就是一个无理数(即无限不循环小数),也是一个超越数,与三角函数有密切关系,与无限级数和有关系。
- 从几何上来说,就是一个比值,特殊图形圆的周长与其直径的比值,也就是单位圆的半周长,还可以是单位圆的面积或圆面积与其半径的平方之比;也有人提出:如果用圆的周长与其半径的比值作为圆周率的话,也是可以的。
-
$\pi$ 是一个常数,目前谷歌宣布已经计算到了 31.4万亿$=3.14\times10^{13}$ 位了,为了纪念 圆周率日-PAI Day(每年的3月14日)。
下面主要阐述 现代分析方法 对计算圆周率的贡献。
多项式 (polynomial) 逼近 (approximate) 未知函数
靠近给定点
>>> f=Function('f')
>>> series(f(x))
f(0) + x*Subs(Derivative(f(_x), _x), _x, 0) + x**2*Subs(Derivative(f(_x), (_x, 2)), _x, 0)/2 + x**3*Subs(Derivative(f(_x), (_x, 3)), _x, 0)/6 + x**4*Subs(Derivative(f(_x), (_x, 4)), _x, 0)/24 + x**5*Subs(Derivative(f(_x), (_x, 5)), _x, 0)/120 + O(x**6)泰勒级数(Taylor series) 实函数或复函数(a real or complex-valued function)
此处
泰勒级数
指数函数(exponential function)
- 指数函数是重要的基本初等函数之一。一般地,$y=a^x$ 函数
$(a$ 为常数且$a>0,a≠1)$ 叫做 指数函数。 - 指数函数的定义域是
$x \in \mathbb{R}$ ; - 值域
$\text{(Domain)};(0,+\infty)$ ; - 单调递增:
$a>1$ 时, 单调递减:$0 < a < 1$ 时。
注意,在指数函数的定义表达式中,在
指数函数应用到值
作为实数变量
指数函数
$\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}$
-
$e^x$ 对$x$ 求导,始终不变,即$\dfrac{\mathbf{d}^{k} }{\mathbf{d}x^k} e^x = e^x$ , - 且
$e^0=1$ . - 剩下的分子 (numerator) 为
$(x − 0)^n$ , 分母 (denominator) 为$n!$ .
欧拉公式有时候记为
>>> series(sin(x),n=10)
x - x**3/6 + x**5/120 - x**7/5040 + x**9/362880 + O(x**10)
>>> series(cos(x),n=10)
1 - x**2/2 + x**4/24 - x**6/720 + x**8/40320 + O(x**10)
>>> series(exp(x),n=10)
1 + x + x**2/2 + x**3/6 + x**4/24 + x**5/120 + x**6/720 + x**7/5040 + x**8/40320 + x**9/362880 + O(x**10)指数函数
$\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}$
令
左边为
右边为 ${\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}}}$
所以
上面也是函数
写成紧凑的求和式为:
$\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}$
$\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),\cos(x),\tan(x)$)的乘积展开式。主要还是代数学中的求根方法。
问题: 求方程
-
首先,
$\sin(x)=0$ 有解${kπ,k=0,\pm 1,\pm 2, \cdots .}$ -
假设
$\sin(x)$ 是多项式函数,由多项式有根的代数基本理论 (the fundamental theorem of algebra) 即 多项式逼近理论 (polynomial approximation theorem)$\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)$ 令
$x \to 0$ , 求极限得到$\displaystyle c=\prod_{k=1}^{\infty} \frac {1}{k^2π^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}$
令
$\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}$
参见 John Wallis' product for $π$
同理可得
$\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}$
$\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}$
通过泰勒级数展开理论和多项式逼近理论这两种不同方法所得到的结果进行比较。
>>> series(sin(x),n=10) # 正弦函数幂级数展开式
x - x**3/6 + x**5/120 - x**7/5040 + x**9/362880 + O(x**10)-
泰勒展开理论得到
$\displaystyle \begin{aligned} \sin(x)&=x-\frac{x^3}{3!}+\frac{x^5}{5!}+\cdots \end{aligned}$ -
多项式逼近理论得到
$\displaystyle \begin{aligned} \sin(x)&= x \prod_{k=1} ^{\infty} (1- \frac{x^2}{(kπ)^2}) \end{aligned}$ -
比较
$x^3$ 的系数可得
$\displaystyle {\begin{aligned} \frac{1}{3!}&= \sum_{k=1} ^{\infty} \frac{1}{(kπ)^2} \end{aligned}}$所以
$\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}$
收敛速度还可以接受。from sympy import summation k = Symbol('k',integer=True) summation(1/k**2,(k,1,oo)) #符号运算可以得到无穷级数和就是π**2/6
计算
$\pi=\sqrt{6 \displaystyle \sum_{k=1}^{\infty}\dfrac{1}{k^2}}$
格雷戈里-莱布尼茨级数于 1671年2月15日提出。利用反正切函数的泰勒级数展开得到
>>> from sympy import *
>>> x,y,z=symbols('x y z')
>>> series(atan(x),n=10) # 反正切函数幂级数展开
x - x**3/3 + x**5/5 - x**7/7 + x**9/9 + O(x**10)反正切函数的级数 (series for the inverse tangent function), 也称为 Gregory's series:
$\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}$
具体推导过程如下:
$\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}$
莱布尼茨公式 (Leibniz formula)
正如你看到,这个级数的收敛极慢!不可取。
$\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}$
This is for pi.
这是计算圆周率的更快一点的收敛方法。(the faster convergent method)
Nilakantha 级数的有理数迭代结果
耗时(s), 迭代次数, 圆周率 π 1.9259201999999997, 4500, 3.1415926535870515825837405507560137150803433030977 3.6562770999999996, 6500, 3.1415926535888833262423877236599992905011247088849 6.4071963, 8500, 3.1415926535893862988637989428921227071088158696038 9.226604299999998, 10000, 3.1415926535895433134507693207779502215449257421397 59.0730983, 20000, 3.1415926535897619931497723041779282156055633567492 166.8244976, 30000, 3.1415926535897839801292611829194198667214211744860 364.8126532, 40000, 3.1415926535897893325056005368286971249174170406760
Viète's formula is the following infinite product of nested radicals representing the mathematical constant
实验证明,迭代200次就已经超出了Python的最大迭代深度(RecursionError: maximum recursion depth exceeded)
耗时(s), 迭代次数, 近似 π 46.814693, 150, 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482 4707897442(90位正确)
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.
$\displaystyle \lim {n\rightarrow \infty }\prod {i=1}^{n}{\frac {a{i}}{2}}={\frac {2}{\pi }}$
where $a_n = \sqrt{2 + a{n − 1}}$, with initial condition
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:
Substituting
Then, expressing each term of the product on the right as a function of earlier terms using the half-angle formula:
gives Viète's formula.
It is also possible to derive from Viète's formula a related formula for
该算法效率最高,计算时间最短,精度也高。170次迭代报错,超出了迭代深度(RecursionError: maximum recursion depth exceeded,缺省是5000)。
耗时(s), 迭代次数, 近似 π 0.3498688000000001, 165, 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
1676年,牛顿给出的方法。令下列
$\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}$
同理可以得到
$\begin{aligned} \ln n! &=\ln1+\ln2+...+\ln n\ &= \sum_{k=1}^{n} \ln k\ &= \int_1^n \ln x \mathbf{d}x \ &= (x \ln x-x)|_1^n\ &= n \ln n-n+1\ &\approx n \ln n-n \end{aligned}$
所以 对于很大的
或
更精确的有:
在GeoGebra中可以轻松实现多项式之和逼近各种函数。
- 先定义次数Order的滑条
$n=slider(1,20,1)$ - 再定义要逼近的函数,如
$f(x)=\arctan(x),g(x)=\sin(x),h(x)=\cos(x),\cdots$ - 调用函数
$g=TaylorPolinomial(f,x(A),n),;A=(0,0)$ - 调用函数
$FormulaText(g, true, true)$ 可以显示级数
代数和几何结合的方法。
采用刘徽割圆术,用正
记 正

单位圆的半径
即圆周率就是半周长,上述算法收敛性很快!
- 先建立迭代次数滑动条
$n=slider(1,10,1)$ - 再建立迭代函数
$f(x)=sqrt(2 - sqrt(4 - x; x))$ - 然后用GGB的迭代命令
$value = Iteration(f, 1, n)\to$ $L_{2n}=\sqrt{2-\sqrt{4-L_n\times L_n}},L_6=1$ ,初始值取正6边形时的值1. - 正
$2n$ 边形的半周长为$\pi=value\times6\times2^{n-1}$
这一算法的收敛也极快,正多边形的边数以指数级增长。边数
Python 源码 参见迭代计算圆周率π的Python源码
采用符号运算得到前10个结论:
12sqrt(2 - sqrt(3)) 24sqrt(2 - sqrt(sqrt(3) + 2)) 48sqrt(2 - sqrt(sqrt(sqrt(3) + 2) + 2)) 96sqrt(2 - sqrt(sqrt(sqrt(sqrt(3) + 2) + 2) + 2)) 192sqrt(2 - sqrt(sqrt(sqrt(sqrt(sqrt(3) + 2) + 2) + 2) + 2)) 384sqrt(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)) 1536sqrt(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)) 6144sqrt(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
-
方法一、在网络上搜索到一个圆周率生成器,只要输入一个数:生成位数,就可以算出该圆周率。没有验证正确否。供大家参考。
-
方法二、在Python环境下,只要调用
sympy.pi.evalf(n+1)就可以得到任意$n$ 位小数的 圆周率$\pi$ .
from sympy import pi
pi.evalf(1001) # 得到1000位小数位的π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 。
在Python环境下,输入了 sympy.pi.evalf(1001) 位数,计算结果如下:
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989