Python中函数的数学集成

Jam*_*rtz 3 python function scipy

我正在尝试集成此功能:

在此输入图像描述

但是我遇到了以下错误:

Traceback (most recent call last):

  File "<ipython console>", line 1, in <module>

  File "siestats.py", line 349, in NormalDistro

    P_inner = scipy.integrate(NDfx,-dev,dev)

TypeError: 'module' object is not callable
Run Code Online (Sandbox Code Playgroud)

我的代码运行这个:

# Definition of the mathematical function:
def NDfx(x):

    return((1/math.sqrt((2*math.pi)))*(math.e**((-.5)*(x**2))))

# This Function normailizes x, u, and o2 (position of interest, mean and st dev) 
# and then calculates the probability up to position 'x'

def NormalDistro(u,o2,x):


    dev = abs((x-u)/o2)


    P_inner = scipy.integrate(NDfx,-dev,dev)

    P_outer = 1 - P_inner

    P = P_inner + P_outer/2

    return(P)
Run Code Online (Sandbox Code Playgroud)

函数NormalDistro意味着导入和使用如下:

foo.NormalDistro(30,2.5,1.25)
Run Code Online (Sandbox Code Playgroud)

举个例子.

DMA*_*361 7

您尝试呼叫的模块是scipy.integrate,您需要调用模块中的一个功能.根据以前对聊天的评论,您可能想要使用 scipy.integrate.quad().

此外,它返回一个元组(Result,MaximumError),所以你不应该P_inner直接使用P你想要的总和P = P_inner[0] + P_outer/2