def trapezoidal(f, a, x, n): h = (x-a)/float(n) I = 0.5*f(a) from scitools.std import iseq for i in iseq(1, n-1): I += f(a + i*h) I += 0.5*f(x) I *= h return I
def trapezoidal(f, a, x, n): h = (x - a) / float(n) I = 0.5 * f(a) from scitools.std import iseq for i in iseq(1, n - 1): I += f(a + i * h) I += 0.5 * f(x) I *= h return I
def __call__(self, x): from scitools.std import iseq f, a, n = self.f, self.a, self.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
def __call__(self, x): from scitools.std import iseq f, a, n = self.f, self.a, self.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
def __call__(self, x): from scitools.std import iseq #from scitools.StringFunction import StringFunction f, a, n = self.f, self.a, self.n #f = StringFunction(f) 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
def __call__(self, x): from scitools.std import linspace, sum, zeros,iseq f, a, n = self.f, self.a, self.n h = (x-a)/float(n) I = 0.5*f(a) ar = zeros(len(linspace(1,n-1, n-1))) for i in iseq(1, n-1): ar[i-1] = f(a + i*h) I = sum(ar) I += 0.5*f(x) I *= h return I
def __call__(self, x): from scitools.std import linspace, sum, zeros, iseq f, a, n = self.f, self.a, self.n h = (x - a) / float(n) I = 0.5 * f(a) ar = zeros(len(linspace(1, n - 1, n - 1))) for i in iseq(1, n - 1): ar[i - 1] = f(a + i * h) I = sum(ar) I += 0.5 * f(x) I *= h return I
def __call__(self, x): from scitools.std import iseq #from scitools.StringFunction import StringFunction f, a, n = self.f, self.a, self.n #f = StringFunction(f) 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
def __call__(self, x): from scitools.std import iseq f, a, n = self.f, self.a, self.n h = (x-a)/float(n) I = 0.5*f(a) l = [] for i in iseq(1, n-1): I = f(a + i*h) l.append(I) I = sum(l) I += 0.5*f(x) I *= h return I
def __call__(self, x): from scitools.std import iseq f, a, n = self.f, self.a, self.n h = (x - a) / float(n) I = 0.5 * f(a) l = [] for i in iseq(1, n - 1): I = f(a + i * h) l.append(I) I = sum(l) I += 0.5 * f(x) I *= h return I