Numerical integration/Adaptive Simpson's method: Difference between revisions
Content added Content deleted
Artoria2e5 (talk | contribs) (Created page with "{{task|Arithmetic operations}} Lychee (1969)'s Modified wp:Adaptive Simpson's Method (doi:10.1145/321526.321537) is a numerical quadrature method that recursively bisects...") |
Artoria2e5 (talk | contribs) No edit summary |
||
Line 19: | Line 19: | ||
delta := left + right - whole |
delta := left + right - whole |
||
tol' := tol / 2 |
|||
'''if''' abs(delta) <= 15 * tol: |
'''if''' depth <= 0 ''or'' tol' == tol ''or'' abs(delta) <= 15 * tol: |
||
'''return''' left + right + delta / 15 |
'''return''' left + right + delta / 15 |
||
'''else''': |
'''else''': |
||
'''return''' _quad_asr(f, a, fa, m, fm, tol |
'''return''' _quad_asr(f, a, fa, m, fm, tol', left , lm, flm, depth - 1) + |
||
_quad_asr(f, m, fm, b, fb, tol |
_quad_asr(f, m, fm, b, fb, tol', right, rm, frm, depth - 1) |
||
'''procedure''' quad_asr(f, a, b, tol, depth) |
'''procedure''' quad_asr(f, a, b, tol, depth) |
Revision as of 14:54, 28 September 2018
Numerical integration/Adaptive Simpson's method
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Lychee (1969)'s Modified Adaptive Simpson's Method (doi:10.1145/321526.321537) is a numerical quadrature method that recursively bisects the interval until the precision is high enough.
; Lychee's ASR, Modifications 1, 2, 3 procedure _quad_asr_simpsons(f, a, fa, b, fb) m := (a + b) / 2 fm := f(m) h := b - a return multiple [m, fm, (h / 6) * (f(a) + f(b) + 4*sum1 + 2*sum2)] procedure _quad_asr(f, a, fa, b, fb, tol, whole, m, fm, depth) lm, flm, left := _quad_asr_simpsons(f, a, fa, m, fm) rm, frm, right := _quad_asr_simpsons(f, m, fm, b, fb) delta := left + right - whole tol' := tol / 2 if depth <= 0 or tol' == tol or abs(delta) <= 15 * tol: return left + right + delta / 15 else: return _quad_asr(f, a, fa, m, fm, tol', left , lm, flm, depth - 1) + _quad_asr(f, m, fm, b, fb, tol', right, rm, frm, depth - 1) procedure quad_asr(f, a, b, tol, depth) fa := f(a) fb := f(b) m, fm, whole := _quad_asr_simpsons(f, a, fa, b, fb) return _quad_asr(f, a, fa, b, fb, tol, whole, m, fm, depth) |