All problems
Adaptive Simpson Decision
Problem
Decide whether an adaptive Simpson step can accept its refined estimate.
f_vals holds f at [a, m_l, m, m_r, b] and width = b - a. Compute the whole-interval estimate S1 = width/6 * (fa + 4 fm + fb) and the refined estimate S2 = width/12 * (fa + 4 fam + 2 fm + 4 fmb + fb). Return [S2, accepted] where accepted is True when |S2 - S1| / 15 < tol.
Hint
The factor 15 comes from Simpson's error expansion when halving the interval.
Test cases
case 1
in: [[0,0.0625,0.25,0.5625,1],1,0.000001]
expected: [0.3333333333333333,true]
case 2
in: [[0,0.00390625,0.0625,0.31640625,1],1,0.001]
expected: [0.20052083333333331,true]
case 3
in: [[0,0.00390625,0.0625,0.31640625,1],1,0.0001]
expected: [0.20052083333333331,false]
case 4
in: [[1,1,1,1,1],2,0.000001]
expected: [2,true]
Starter codePython
def adaptive_simpson_decision(f_vals, width, tol):
# Return [refined_estimate, accepted]
# Your code here
pass4 test cases · run your code against them in the editor