All problems
Romberg One Step
Problem
Apply one step of Romberg integration to f(x) = sum(coeffs[i] * x^i) on [a, b].
Compute the composite trapezoidal rule with n subintervals (t1) and with 2n subintervals (t2), then return the extrapolated value (4*t2 - t1) / 3. Assume n >= 1.
Hint
Romberg combines two trapezoidal approximations to cancel the leading error term.
Test cases
case 1
in: [[0,0,1],0,2,2]
expected: 2.6666666666666665
case 2
in: [[0,0,0,1],0,1,1]
expected: 0.25
case 3
in: [[1],0,3,1]
expected: 3
case 4
in: [[0,0,0,0,1],0,1,2]
expected: 0.20052083333333334
Starter codePython
def romberg_one_step(coeffs, a, b, n):
# Your code here
pass4 test cases · run your code against them in the editor