Changed trapezoidulation algorithm