我有一个Python程序来计算一个函数在一个点上的积分。但这根本不有效,因为我想同时计算更多的x值,而不仅仅是一个值。有人知道吗?你知道吗
from scitools.std import *
def trapezoidal(f,a,x,n):
h = (x-a)/float(n)
I = 0.5*f(a)
for i in iseq(1, n-1):
I += f(a+i*h)
I += 0.5*f(x)
I *= h
return I
class Integral:
def __init__(self, f, a, n=100):
self.f, self.a, self.n = f,a,n
def __call__(self,x):
return trapezoidal(self.f,self.a,x,self.n)
目前没有回答
相关问题 更多 >
编程相关推荐