python - 将高斯与四边形集成时突然下降

标签 python gaussian quad

我正在尝试将 u -> exp(-u²/2) 从 -infinity 积分到 x。当我绘制函数时,在 21 左右突然下降,在 36 左右下降到 0,而它应该大致恒定为 2.5。怎么解释?

import numpy as np
from scipy.integrate import quad
import matplotlib.pyplot as plt

def intExp(x):
    return quad(lambda u: np.math.exp(-u*u/2),-np.Inf, x, full_output=0)

def plot(a,b, u, v,s):
    plt.close()
    t = np.arange(a,b,s)
    plt.plot(t , map(intExp,t))
    plt.axis([a, b, u, v])
    plt.show()

plot(-10, 50, -1, 3, 1)

感谢您的帮助!

最佳答案

与步宽有关。将 epsabs 从默认值更改为 1e-9 有效:

import numpy as np
from scipy.integrate import quad
import matplotlib.pyplot as plt

def intExp(x):
    return quad(lambda u: np.math.exp(-u*u/2),-np.Inf, x, full_output=0,epsabs=1e-9)

def plot(a,b, u, v,s):
    plt.close()
    t = np.arange(a,b,s)
    plt.plot(t , map(intExp,t))
    plt.axis([a, b, u, v])
    plt.show()


plot(-10, 50, -1, 3, 1)

关于python - 将高斯与四边形集成时突然下降,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31194860/

相关文章:

Python 与 MATLAB 计算无穷大的积分,结果不同,替代方案(即将 Gauss-Legendre 正交扩展到 -x-> Infinity)?

Python 3 urllib urlparse URL解析

python - 高斯过程 scikit-learn - 异常

python - 在python中将高斯拟合到吸收线

matlab - 计算点p到高维高斯(M,V)的距离

python - 如何有意使具有错误打印输出的Python代码崩溃(“IntegrationWarning”)

python - 将 Pandas 数据框列值合并到新列中

python - 分割 str 的字典理解

python - PyQtGraph PlotWidget : how to force each draw (changing range) for "real time" plotting

带集成的 NumPy 矢量化