欧拉公式是数学中最重要的公式之一, 它涉及到了复数, 无理数, 三角函数, 简单优美
eiθ=cos(θ)+isin(θ)e^{i\theta} = cos(\theta) + isin(\theta)eiθ=cos(θ)+isin(θ)
欧拉公式代表的含义并不是欧拉最先发现的, 1714年英国物理学家和数学家罗杰·柯茨在一个公式中建立了对数, 三角函数和虚数之间的关系, 在1740年前后, 欧拉通过另一种形式得到了等价的公式.
iθ=ln(cos(θ)+isin(θ))i\theta = ln\left(cos(\theta) + isin(\theta)\right)iθ=ln(cos(θ)+isin(θ))
如果把 θ\thetaθ 的值特殊化为 θ=π\theta = \piθ=π,就得到了欧拉恒等式
eπi=−1e^{\pi i} = -1eπi=−1
自然常数e是一个特殊的常数, 它的特性是 $ \left ( e^{x} \right )’ = e^{x} $, 即指数函数的导数还是自身
e的定义如下
$e = \lim_{x \to 0} (1 + x)^{\frac{1}{x}} $
或
e=limx→∞(1+1x)xe = \lim_{x \to \infty} (1 + \frac{1}{x})^{x}e=limx→∞(1+x1)x
这个极限收敛, 值约为2.71828
对 exe^xex 的导数不变性的证明:
因为当e趋于无穷小时, $e = \lim_{x \to 0} (1 + x)^{\frac{1}{x}} $ (这里实际上包含一个物理意义, 在 limx→0\lim_{x \to 0}limx→0 时 exe^xex 和 y=xy=xy=x 的曲线是无限接近的)
对其变形可得
ex=limx→01+xe^x = lim_{x \to 0}1 + xex=limx→01+x,
x=limx→0ex−1x = lim_{x \to 0}e^x - 1x=limx→0ex−1,
1=limx→0ex−1x1 = lim_{x \to 0} \frac{e^{x} - 1}{x}1=limx→0xex−1,
于是根据导数的定义,对于 exe^xex, 我们给自变量x一个微小增量dx,可以得到
y′=e(x+dx)−exdxy' = \frac{e^{(x+dx)}-e^{x}}{dx}y′=dxe(x+dx)−ex
=ex∗edx−exdx= \frac{e^x * e^{dx} - e^x}{dx}=dxex∗edx−ex
=ex∗edx−1dx= e^x * \frac{e^{dx} - 1}{dx}=ex∗dxedx−1, 将上面的等式代入
=ex∗1=ex=y= e^x * 1 = e^x = y=ex∗1=ex=y
f(x)=exf(x) = e^xf(x)=ex 的泰勒级数展开
exp(x)=1+x11!+x22!+x33!+...=∑i=0nxnn!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\thetax=iθ 时, exp(iθ)exp(i\theta)exp(iθ) 就成为了复平面上的一个圆
ei(0+2nπ)=1e^{i(0 + 2n\pi)} = 1ei(0+2nπ)=1
ei(π2+2nπ)=ie^{i(\frac{\pi}{2} + 2n\pi)} = iei(2π+2nπ)=i
ei(π+2nπ)=−1e^{i(\pi + 2n\pi)} = -1ei(π+2nπ)=−1
ei(3π2+2nπ)=−ie^{i(\frac{3\pi}{2} + 2n\pi)} = -iei(23π+2nπ)=−i
用一小段c代码验证 ei(π+2nπ)=−1e^{i(\pi + 2n\pi)} = -1ei(π+2nπ)=−1
#define PI 3.1415926
#define STEP 18int 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.1415931 - 9.869604 / 2 = 4.934802, -3.934802 3.1415932 - 31.006275 / 6 = 5.167713, -3.934802 -2.0261203 - 97.409084 / 24 = 4.058712, 0.123910 -2.0261204 - 306.019659 / 120 = 2.550164, 0.123910 0.5240445 - 961.389095 / 720 = 1.335263, -1.211353 0.5240446 - 3020.292867 / 5040 = 0.599264, -1.211353 -0.0752217 - 9488.529721 / 40320 = 0.235331, -0.976022 -0.0752218 - 29809.094757 / 362880 = 0.082146, -0.976022 0.0069259 - 93648.031501 / 3628800 = 0.025807, -1.001829 0.00692510 - 294203.962770 / 39916800 = 0.007370, -1.001829 -0.00044511 - 924268.992327 / 479001600 = 0.001930, -0.999900 -0.00044512 - 2903676.626705 / 6227020800 = 0.000466, -0.999900 0.00002113 - 9122169.003250 / 87178291200 = 0.000105, -1.000004 0.00002114 - 28658138.636560 / 1307674368000 = 0.000022, -1.000004 -0.00000115 - 90032196.270391 / 20922789888000 = 0.000004, -1.000000 -0.00000116 - 282844481.564807 / 355687428096000 = 0.000001, -1.000000 0.00000017 - 888582130.234833 / 6402373705728000 = 0.000000, -1.000000 0.000000
欧拉公式中, cos(θ)cos(\theta)cos(θ)是实部, sin(θ)sin(\theta)sin(θ)是虚部, 分别可以表示为
cos(x)=1−x22!+x44!+...=∑i=0n(−1)nx2n2n!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
sin(x)=x11!−x33!+x55!−...=∑i=0n(−1)nx2n+1(2n+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 以及其派生出的其他数值, 都可以通过泰勒级数进行计算, 根据需要可以通过循环次数控制精度.