All problems
Midpoint versus Trapezoid Estimate
Problem
Compare the composite midpoint and trapezoidal rules on n equal subintervals of [a, b] for a polynomial: the midpoint rule samples at subinterval centers, the trapezoid rule at the nodes.
Return [midpoint, trapezoid].
Hint
Midpoint uses (i + 0.5) * h; trapezoid sums interior nodes with full weight.
Test cases
case 1
in: [[0,0,1],0,1,2]
expected: [0.3125,0.375]
case 2
in: [[1],0,2,4]
expected: [2,2]
case 3
in: [[0,0,0,1],0,2,2]
expected: [3.5,5]
Starter codePython
def midpoint_versus_trapezoid(coeffs, a, b, n):
# Your code here
pass3 test cases · run your code against them in the editor