我试图用梯形rul数值积分正态分布函数:
import math as m
def f(x):
N(x)
return x
def N(x):
x=((2*m.pi)**-(1/2))*m.e(-(1/2)*x**2)
return x
def trap(a, b, n):
h = float(b - a) / n
t = 0.0
for i in range(1, n):
t += f(a + i*h)
t += (f(a)+f(b))/2.0
return t * h
n=int(raw_input("the value of n is:"))
a=int(raw_input("the value of a is:"))
b=int(raw_input("the value of b is:"))
print(trap(a,b,n))
但是,当我试着打电话
^{pr2}$我在第15行N中得到以下错误:
TypeError: 'float' object is not callable
math.e
是常数2.71。。。这是一个浮点数,不是一个可调用的。指数函数是math.exp
相关问题 更多 >
编程相关推荐