欧拉公式是数学中最重要的公式之一, 它涉及到了复数, 无理数, 三角函数, 简单优美
e i θ = c o s ( θ ) + i s i n ( θ ) e^{i\theta} = cos(\theta) + isin(\theta) eiθ=cos(θ)+isin(θ)
欧拉公式代表的含义并不是欧拉最先发现的, 1714年英国物理学家和数学家罗杰·柯茨在一个公式中建立了对数, 三角函数和虚数之间的关系, 在1740年前后, 欧拉通过另一种形式得到了等价的公式.
i θ = l n ( c o s ( θ ) + i s i n ( θ ) ) i\theta = ln\left(cos(\theta) + isin(\theta)\right) iθ=ln(cos(θ)+isin(θ))
如果把 θ \theta θ 的值特殊化为 θ = π \theta = \pi θ=π,就得到了欧拉恒等式
e π i = − 1 e^{\pi i} = -1 eπi=−1
自然常数e
自然常数e是一个特殊的常数, 它的特性是 $ \left ( e^{x} \right )’ = e^{x} $, 即指数函数的导数还是自身
e的定义如下
$e = \lim_{x \to 0} (1 + x)^{\frac{1}{x}} $
或
e = lim x → ∞ ( 1 + 1 x ) x e = \lim_{x \to \infty} (1 + \frac{1}{x})^{x} e=limx→∞(1+x1)x
这个极限收敛, 值约为2.71828
对 e x e^x ex 的导数不变性的证明:
因为当e趋于无穷小时, $e = \lim_{x \to 0} (1 + x)^{\frac{1}{x}} $ (这里实际上包含一个物理意义, 在 lim x → 0 \lim_{x \to 0} limx→0 时 e x e^x ex 和 y = x y=x y=x 的曲线是无限接近的)
对其变形可得
e x = l i m x → 0 1 + x e^x = lim_{x \to 0}1 + x ex=limx→01+x,
x = l i m x → 0 e x − 1 x = lim_{x \to 0}e^x - 1 x=limx→0ex−1,
1 = l i m x → 0 e x − 1 x 1 = lim_{x \to 0} \frac{e^{x} - 1}{x} 1=limx→0xex−1,
于是根据导数的定义,对于 e x e^x ex, 我们给自变量x一个微小增量dx,可以得到
y ′ = e ( x + d x ) − e x d x y' = \frac{e^{(x+dx)}-e^{x}}{dx} y′=dxe(x+dx)−ex
= e x ∗ e d x − e x d x = \frac{e^x * e^{dx} - e^x}{dx} =dxex∗edx−ex
= e x ∗ e d x − 1 d x = e^x * \frac{e^{dx} - 1}{dx} =ex∗dxedx−1, 将上面的等式代入
= e x ∗ 1 = e x = y = e^x * 1 = e^x = y =ex∗1=ex=y
自然常数e的指数函数
f ( x ) = e x f(x) = e^x f(x)=ex 的泰勒级数展开
e x p ( x ) = 1 + x 1 1 ! + x 2 2 ! + x 3 3 ! + . . . = ∑ i = 0 n x n n ! exp(x) = 1 + \frac{x^1}{1!} + \frac{x^2}{2!} + \frac{x^3}{3!} + ... = \sum_{i=0}^{n} \frac{x^n}{n!} exp(x)=1+1!x1+2!x2+3!x3+...=∑i=0nn!xn
当 x = i θ x = i\theta x=iθ 时, e x p ( i θ ) exp(i\theta) exp(iθ) 就成为了复平面上的一个圆
e i ( 0 + 2 n π ) = 1 e^{i(0 + 2n\pi)} = 1 ei(0+2nπ)=1
e i ( π 2 + 2 n π ) = i e^{i(\frac{\pi}{2} + 2n\pi)} = i ei(2π+2nπ)=i
e i ( π + 2 n π ) = − 1 e^{i(\pi + 2n\pi)} = -1 ei(π+2nπ)=−1
e i ( 3 π 2 + 2 n π ) = − i e^{i(\frac{3\pi}{2} + 2n\pi)} = -i ei(23π+2nπ)=−i
数值验证
用一小段c代码验证 e i ( π + 2 n π ) = − 1 e^{i(\pi + 2n\pi)} = -1 ei(π+2nπ)=−1
#define PI 3.1415926
#define STEP 18
int main(void)
{
int32_t i = 0;
int64_t factorial = 1;
double real = 1, imaginary = 0, pp = 1, curr;
for (i = 0; i < STEP; i++)
{
pp = pp * PI;
factorial = factorial * (i + 1);
curr = pp / factorial;
if (i % 4 == 0) imaginary += curr;
else if (i % 4 == 1) real -= curr;
else if (i % 4 == 2) imaginary -= curr;
else real += curr;
printf("%3d - %20.6f / %25lu = %f, %10f %10f\r\n", i, pp, factorial, curr, real, imaginary);
}
}
当step为18时, 其输出为
0 - 3.141593 / 1 = 3.141593, 1.000000 3.141593
1 - 9.869604 / 2 = 4.934802, -3.934802 3.141593
2 - 31.006275 / 6 = 5.167713, -3.934802 -2.026120
3 - 97.409084 / 24 = 4.058712, 0.123910 -2.026120
4 - 306.019659 / 120 = 2.550164, 0.123910 0.524044
5 - 961.389095 / 720 = 1.335263, -1.211353 0.524044
6 - 3020.292867 / 5040 = 0.599264, -1.211353 -0.075221
7 - 9488.529721 / 40320 = 0.235331, -0.976022 -0.075221
8 - 29809.094757 / 362880 = 0.082146, -0.976022 0.006925
9 - 93648.031501 / 3628800 = 0.025807, -1.001829 0.006925
10 - 294203.962770 / 39916800 = 0.007370, -1.001829 -0.000445
11 - 924268.992327 / 479001600 = 0.001930, -0.999900 -0.000445
12 - 2903676.626705 / 6227020800 = 0.000466, -0.999900 0.000021
13 - 9122169.003250 / 87178291200 = 0.000105, -1.000004 0.000021
14 - 28658138.636560 / 1307674368000 = 0.000022, -1.000004 -0.000001
15 - 90032196.270391 / 20922789888000 = 0.000004, -1.000000 -0.000001
16 - 282844481.564807 / 355687428096000 = 0.000001, -1.000000 0.000000
17 - 888582130.234833 / 6402373705728000 = 0.000000, -1.000000 0.000000
应用
欧拉公式中, c o s ( θ ) cos(\theta) cos(θ)是实部, s i n ( θ ) sin(\theta) sin(θ)是虚部, 分别可以表示为
c o s ( x ) = 1 − x 2 2 ! + x 4 4 ! + . . . = ∑ i = 0 n ( − 1 ) n x 2 n 2 n ! cos(x) = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} + ... = \sum_{i=0}^{n} (-1)^n\frac{x^{2n}}{2n!} cos(x)=1−2!x2+4!x4+...=∑i=0n(−1)n2n!x2n
s i n ( x ) = x 1 1 ! − x 3 3 ! + x 5 5 ! − . . . = ∑ i = 0 n ( − 1 ) n x 2 n + 1 ( 2 n + 1 ) ! sin(x) = \frac{x^1}{1!} - \frac{x^3}{3!} + \frac{x^5}{5!} - ... = \sum_{i=0}^{n} (-1)^n\frac{x^{2n + 1}}{(2n+1)!} sin(x)=1!x1−3!x3+5!x5−...=∑i=0n(−1)n(2n+1)!x2n+1
这样就建立了三角函数和普通指数运算的桥梁, 在计算机上, 计算三角函数 sin, cos 以及其派生出的其他数值, 都可以通过泰勒级数进行计算, 根据需要可以通过循环次数控制精度.