Пример #1
0
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
Пример #2
0
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
Пример #3
0
 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
Пример #4
0
 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
Пример #5
0
 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
Пример #6
0
 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
Пример #7
0
 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
Пример #8
0
 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
Пример #9
0
 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
Пример #10
0
 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