Python 求高斯误差函数 erf、erfc、erfi

35 篇文章 27 订阅

Part.I Introduction

本文将对误差函数(ERror Function, ERF)进行简单的介绍,并探索如何用 Python 来求误差函数。

在这里插入图片描述

更多与之相关的理论知识可以参看 关于高斯函数 / 高斯分布 / 高斯误差函数的探讨

Part.II 概念定义

Chap.I 误差函数 erf

误差函数(ERror Function, ERF)的定义式如下
erf ⁡ ( x ) = 2 π ∫ 0 x e − t 2 d t \operatorname{erf}(x)=\frac{2}{\sqrt{\pi}}\int_{0}^{x} e^{-t^2}dt erf(x)=π 20xet2dt

Chap.II 误差函数补 erfc

有的地方叫做『误差补函数』或『互补误差函数』,这里我随意取成了误差函数补(ERror Function Complement, ERFC)。一是参考了『舒尔补』这一名字,二是和字母顺序保持一致。

误差函数补(ERror Function Complement, ERFC)的定义式如下

erfc ⁡ ( x ) = 1 − erf ⁡ ( x ) = 2 π ∫ x ∞ e − t 2 d t \operatorname{erfc}(x)=1-\operatorname{erf}(x)=\frac{2}{\sqrt{\pi}}\int_{x}^{\infty} e^{-t^2}dt erfc(x)=1erf(x)=π 2xet2dt

PS: 2 π ∫ 0 ∞ e − t 2 d t = 1 \frac{2}{\sqrt{\pi}}\int_{0}^{\infty} e^{-t^2}dt=1 π 20et2dt=1

Chap.III 虚误差函数 erfi

虚误差函数(Virtual error function)的定义式如下:
erfci ⁡ ( x ) = − i erf ⁡ ( i x ) = 1 π ∫ − x x e t 2 d t = 2 π ∫ 0 x e t 2 d t \operatorname{erfci}(x)=-i\operatorname{erf}(ix)=\frac{1}{\sqrt{\pi}}\int_{-x}^{x}e^{t^2}dt=\frac{2}{\sqrt{\pi}}\int_{0}^{x}e^{t^2}dt erfci(x)=ierf(ix)=π 1xxet2dt=π 20xet2dt

另外有 erfci ⁡ ( i x ) = i erfc ⁡ ( x ) \operatorname{erfci}(ix)=i\operatorname{erfc}(x) erfci(ix)=ierfc(x)

Part.II 求值与绘图

Chap.I 求取方式

其实很简单

import math

math.erf(x)
math.erfc(x)

比如

>>> import math
>>> math.erf(1)
0.8427007929497149
>>> math.erfc(1)
0.1572992070502851
>>> 1-math.erf(1)
0.1572992070502851

GeoGebra 验证如下:

在这里插入图片描述

Chap.II 绘图

使用下面的代码可以绘制处误差函数和误差函数补的图像

import math
import matplotlib.pyplot as plt

def plot_erf():
    x=list(range(0,200))
    x=[i*0.02 for i in x]
    y1=[math.erf(i) for i in x]
    y2=[math.erfc(i) for i in x]
    plt.plot(x,y1)
    plt.plot(x,y2)
    plt.legend(["erf","erfc"])
    plt.show()

plot_erf()

绘图结果为:
在这里插入图片描述

Reference

  • 29
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

流浪猪头拯救地球

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值