class Trapezoidal:
    def __init__(self, a, b, n):
        self.a = a
        self.b = b
        self.n = n

    def constructMethod(self):
        h = (self.b - self.a)/float(self.n - 1)
        x = [self.a + i*h for i in range(self.n)]
        w = [h for i in range(self.n)]

        #Randpunkte
        w[0] /= 2
        w[-1] /= 2

        return x, w

    def integrate(self, f):
        x, w = self.constructMethod()
        s = 0
        for i in range(len(w)):
            s += w[i]*f(x[i])

        return s

    def __call__(self, f):
        return self.integrate(f)
