Integration COS 323 Numerical Integration Problems • Basic 1D numerical integration: – Given ability to evaluate f (x) for any x, find – Goal:
Download ReportTranscript Integration COS 323 Numerical Integration Problems • Basic 1D numerical integration: – Given ability to evaluate f (x) for any x, find – Goal:
Integration
COS 323
Numerical Integration Problems • Basic 1D numerical integration: – Given ability to evaluate
f
(
x
) for any
x
, find – Goal: best accuracy with fewest samples
b a
f
(
x
)
dx
• Other problems (future lectures): – Improper integration – – – Multi-dimensional integration Ordinary differential equations Partial differential equations
Trapezoidal Rule • Approximate function by trapezoid f(a) f(b) a b
Trapezoidal Rule
b a
f
(
x
)
dx
(
b
a
)
f
(
a
)
f
(
b
) 2 f(a) a b f(b)
Extended Trapezoidal Rule
b a
f
(
x
)
dx
(
b
a
)
f
(
a
)
f
(
b
) 2 Divide into segments of width
h
: f(a) a
b a
f
(
x
)
dx
h
2 1
f
(
a
)
f
(
x
1 ) a
f
(
x n
1 ) 1 2
f
(
b
) b b f(b)
Trapezoidal Rule Error Analysis • How accurate is this approximation?
a
b f
(
x
)
dx
(
b
a
)
f
2 (
a
)
f
(
b
) E • Start with Taylor series for
f
(
x
) around
a f
(
x
)
f
(
a
) (
x
a
)
f
(
a
) 1 2 (
x
a
) 2
f
(
a
)
Trapezoidal Rule Error Analysis • Expand LHS:
a
b f
(
x
)
dx
(
b
a
)
f
(
a
) 1 2 (
b
a
) 2
f
(
a
) 1 6 (
b
a
) 3
f
(
a
) • Expand RHS (
b
a
)
f
2 1 2 (
a
) (
b
a
)
f f
(
b
) E (
a
) 1 2 (
b
a
) 1 2 (
b
a
) 2
f
(
a
)
f
(
a
) 1 4 (
b
a
) 3
f
(
a
) E
Trapezoidal Rule Error Analysis • So, E 1 12 (
b
a
) 3
f
(
a
) • In general, error for a
single
proportional to
h
3 segment • Error for subdividing entire a b interval proportional to
h
2 – “Cubic local accuracy, quadratic global accuracy”
Determining Step Size • Change in integral when reducing step size is a reasonable guess for accuracy • For trapezoidal rule, easy to go from h without wasting previous samples h/2 a b
Simpson’s Rule • Approximate integral by parabola through three points f(a) a
b a
f
(
x
)
dx
h
3
f
(
a
) 4
f
(
a
h
)
f
(
b
)
O
(
h
5 ) • Better accuracy for same # of evaluations b f(b)
Richardson Extrapolation • Better way of getting higher accuracy for a given # of samples • Suppose we’ve evaluated integral for step size h and step size h/2:
F h
F h
/ 2
F F
h
2 2 2
h
4 2 4 • Then 4 3
F h
/ 2 1 3
F h
F
O
(
h
4 )
Richardson Extrapolation • This treats the approximation as a function of h and “extrapolates” the result to h=0 • Can repeat:
F h
–1/3 4/3 –1/15
F h
/ 2 16/15 –1/63 64/63
F h
/ 4
F h
/ 8
O
(
h
2 )
O
(
h
4 )
O
(
h
6 )
O
(
h
8 )
Open Methods • Trapezoidal rule won’t work if function undefined at one of the points where evaluating – Most often: function infinite at one endpoint • 1 0
dx x
2 Open methods only evaluate function on the
open
interval (i.e., not at endpoints)
Midpoint Rule • Approximate function by rectangle evaluated at midpoint
f
(
a
b
) 2 a b
Extended Midpoint Rule
b a
f
(
x
)
dx
(
b
a
)
f
(
a
b
) 2 Divide into segments of width
h
: a
b a
f
(
x
)
dx
h
f
(
a
h
2 ) a
f
(
a
3
h
) 2
f
(
b
h
2 ) b b
Midpoint Rule Error Analysis • Following similar analysis to trapezoidal rule, find that local accuracy is cubic, quadratic global accuracy • Formula suitable for adaptive method, Richardson extrapolation, but can’t halve intervals without wasting samples
Discontinuities • All the above error analyses assumed nice (continuous, differentiable) functions • In the presence of a discontinuity, all methods revert to accuracy proportional to h • Locally-adaptive methods: do not subdivide all intervals equally, focus on those with large error (estimated from change with a single subdivision)