什么是误差函数表计算器?
这款工具可以针对一组连续的 x 值,生成高斯误差函数 \(\operatorname{erf}(x)\) 与互补误差函数 \(\operatorname{erfc}(x)\) 的数值表。误差函数广泛出现在概率论、统计学、热传导和扩散问题中。它是一个纯数学的特殊函数工具,因此在任何国家和场景下计算结果都完全一致。
使用方法
只需输入三个数字:x 的初始值(即第一行的取值)、每一行依次累加的步长(增量),以及迭代次数(行数)。计算器按照 $$x_i = \text{Initial }x + i \cdot \text{Increment}, \quad i = 0,1,\dots,\text{Rows}-1$$ 依次生成各行,并输出每一行对应的 \(\operatorname{erf}(x)\) 与 \(\operatorname{erfc}(x)\)。步长可以为负数(生成递减表格),也可以为零(此时各行数值完全相同)。
计算公式
$$\operatorname{erf}(x) = \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^{2}}\,dt, \qquad \operatorname{erfc}(x) = 1 - \operatorname{erf}(x)$$ 本工具采用 Abramowitz & Stegun 手册 7.1.26 节的有理函数近似公式进行计算(最大误差约为 \(1.5\times10^{-7}\));对于负数参数,则利用奇对称性 \(\operatorname{erf}(-x) = -\operatorname{erf}(x)\) 求值。
计算示例
若初始值取 0、步长取 0.5、行数取 5,则会得到 \(x = 0、0.5、1.0、1.5、2.0\)。此时 \(\operatorname{erf}(1.0) \approx 0.8427008\),\(\operatorname{erfc}(1.0) \approx 0.1572992\),且 \(\operatorname{erf}(1.0) + \operatorname{erfc}(1.0) = 1\),正好验证了二者之和恒等于 1 的关系。
常见 erf(x) 与 erfc(x) 参考值
高斯误差函数为 \(\operatorname{erf}(x) = \frac{2}{\sqrt{\pi}}\int_0^x e^{-t^2}\,dt\),互补误差函数为 \(\operatorname{erfc}(x) = 1 - \operatorname{erf}(x)\)。下表列出了广泛使用的数值,四舍五入至 7 位小数。您可以用起始值 = 0、步长 = 0.5 和 7 行来重现该表。
| x | erf(x) | erfc(x) |
|---|---|---|
| 0 | 0.0000000 | 1.0000000 |
| 0.5 | 0.5204999 | 0.4795001 |
| 1 | 0.8427008 | 0.1572992 |
| 1.5 | 0.9661051 | 0.0338949 |
| 2 | 0.9953223 | 0.0046777 |
| 2.5 | 0.9995930 | 0.0004070 |
| 3 | 0.9999779 | 0.0000221 |
对称性:erf 是奇函数,因此 \(\operatorname{erf}(-x) = -\operatorname{erf}(x)\),进而 \(\operatorname{erfc}(-x) = 1 + \operatorname{erf}(x) = 2 - \operatorname{erfc}(x)\)。随着 x 增大,erf(x) 趋近于 1,erfc(x) 趋近于 0。
erf 与 erfc 数值的解读
与正态分布的联系。 标准正态累积分布函数为
$$\Phi(z) = \tfrac{1}{2}\left[1 + \operatorname{erf}\left(\frac{z}{\sqrt{2}}\right)\right]$$
对于均值为 μ、标准差为 σ 的正态变量 X,erf(x) 是其落在均值 x·σ·√2 范围内的概率:
$$P\left(|X-\mu| \le x\,\sigma\sqrt{2}\right) = \operatorname{erf}(x)$$
示例:
- \(\operatorname{erf}(1/\sqrt{2}) \approx 0.6827\):约 68.27% 的取值位于 ±1σ 之内。
- \(\operatorname{erf}(2/\sqrt{2}) \approx 0.9545\):约 95.45% 的取值位于 ±2σ 之内。
- \(\operatorname{erf}(3/\sqrt{2}) \approx 0.9973\):约 99.73% 的取值位于 ±3σ 之内。
erfc 作为尾部概率。 erfc(x) 是落在该中心区间之外的概率,即两侧尾部概率之和。以 Q(z) = 1 − Φ(z) 作为上尾概率,则 \(\operatorname{erfc}(x) = 2\,Q(x\sqrt{2})\)。例如,erfc(1/√2) ≈ 0.3173,即落在 ±1σ 之外的双侧概率。
精度说明。 许多快速实现使用有理逼近(例如 Abramowitz 和 Stegun 公式),其最大绝对误差约为 1.5×10⁻⁷。对于 erf(x) 本身,这已经足够;但当 x 较大时,erfc(x) = 1 − erf(x) 会变得非常小(erfc(3) ≈ 2.2×10⁻⁵,erfc(5) ≈ 1.5×10⁻¹²)。绝对误差 10⁻⁷ 因此会使远尾值中的大部分甚至全部有效数字失效。对于大 x 时的极小 erfc 值,应视为近似值;如果需要精确的极端尾部概率,请使用专门的高精度 erfc 例程。
常见问题
erf 的取值范围是多少? \(\operatorname{erf}(x)\) 的取值落在 \((-1, 1)\) 之间;其中 \(\operatorname{erf}(0) = 0\),\(\operatorname{erf}(+\infty) = 1\),\(\operatorname{erf}(-\infty) = -1\)。
那 erfc 呢? \(\operatorname{erfc}(x)\) 的取值落在 \((0, 2)\) 之间:\(\operatorname{erfc}(0) = 1\),\(\operatorname{erfc}(+\infty) = 0\),\(\operatorname{erfc}(-\infty) = 2\)。
最多可以生成多少行? 行数必须为正整数;为了保证输出结果便于查看,表格最多支持 2000 行。