cis541 07 integration.pptweb.cse.ohio-state.edu/~parent.1/classes/541/lectures/cis541_07... · •...
Post on 23-Feb-2020
9 Views
Preview:
TRANSCRIPT
1
Numerical Integration
Roger Crawfis
February 7, 2012 OSU/CSE 541 2
Quadrature
• We talk in terms of Quadrature Rules– 1. The process of making something square. 2.
Mathematics The process of constructing a square equal in area to a given surface. 3. Astronomy A configuration in which the position of one celestial body is 90° from another celestial body, as measured from a third.
– The American Heritage® Dictionary: Fourth Edition. 2000
2
February 7, 2012 OSU/CSE 541 3
Outline
• Definite Integrals• Lower and Upper Sums
– Reimann Integration or Reimann Sums
• Uniformly-spaced samples– Trapezoid Rules– Romberg Integration– Simpson’s Rules– Adaptive Simpson’s Scheme
• Non-uniformly spaced samples– Gaussian Quadrature Formulas
February 7, 2012 OSU/CSE 541 4
What does an integral represent?
Basic definition of an integral:
Motivation
b
adxxf area)(
d
c
b
adxdyxf volume)(
n
kk
b
a nxxfdxxf
1
)(lim)(
sum of height width
f(x)
x
n
abx
where
3
February 7, 2012 OSU/CSE 541 5
• Evaluate the integral, without doing the calculation analytically.
• Necessary when either:
– Integrand is too complicated to integrate analytically
– Integrand is not precisely defined by an equation, i.e., we are given a set of data (xi, yi), i = 1, 2, 3, …,n
Motivation
b
adxxfI )(
dxex
x x5.02
0 5.01
)1cos(2
February 7, 2012 OSU/CSE 541 6
• Integration is a summing process. Thus virtually all numerical approximations can be represented by
in which wi are the weights, xi are the sampling points, and Et is the truncation error
• Valid for any function that is continuous on the closed and bounded interval of integration.
t
b
a i
n
ii ExfwdxxfI
)()(1
Reimann Integral Theorem
4
February 7, 2012 OSU/CSE 541 7
• The most common numerical integration formula is based on equally spaced data points.
• Divide [x0 , xn] into n intervals (n1)
nx
xdxxf
0
)(
Partitioning the Integral
1 2
00 1 1
( ) ( ) ( ) ( )n
n
n
xx xx
xx x x
f x dx f x f x f x
February 7, 2012 OSU/CSE 541 8
Upper Sums
• Assume that f(x)>0 everywhere.
• If within each interval, we could determine the maximum value of the function, then we have:
• where
0
1
10
( )nx n
i i iix
f x M x x
1sup ( ) :i i iM f x x x x Supremum - least upper bound
5
February 7, 2012 OSU/CSE 541 9
Upper Sums
• Graphically:
x0 x1 x2 x4x3
February 7, 2012 OSU/CSE 541 10
Lower Sums
• Likewise, still assuming that f(x)>0 everywhere.
• If within each interval, we could determine the minimum value of the function, then we have:
• where
0
1
10
( )nx n
i i iix
f x m x x
1inf ( ) :i i im f x x x x Infimum - greatest
lower bound
6
February 7, 2012 OSU/CSE 541 11
Lower Sums
• Graphically
x0 x1 x2 x4x3
February 7, 2012 OSU/CSE 541 12
Finer Partitions
• We now have a bound on the integral of the function for some partition (x0,..,xn):
• As n, one would assume that the sum of the upper bounds and the sum of the lower bounds approach each other.
• This is the case for most functions, and we call these Riemann-integrable functions.
0
1 1
1 10 0
( )nxn n
i i i i i ii ix
m x x f x M x x
7
February 7, 2012 OSU/CSE 541 13
Bounding the Integral
• Graphically
x0 x1 x2 x4x3
February 7, 2012 OSU/CSE 541 14
Bounding the Integral
• Halving each interval (much like Lab1):
x0 x3 x5 x9x7
8
February 7, 2012 OSU/CSE 541 15
Bounding the Integral
• One more time:
x0 x5 x7 x11x9
February 7, 2012 OSU/CSE 541 16
Monotonic Functions
• Note that if a function is monotonically increasing (or decreasing), then the lower sum corresponds to the left partition values, and the upper sum corresponds to the right partition values.
x0 x3 x5 x9x7
9
February 7, 2012 OSU/CSE 541 17
Lab1 and Integration
• Thinking back to lab1, what were the limits or the integration?
• Is the sin function monotonic on this interval?
• Should the Reiman sum be an upper or lower sum?
February 7, 2012 OSU/CSE 541 18
Polynomial Approximation
• Rather than search for the maximum or minimum, we replace f(x) with a known and simple function.
• Within each interval we approximate f(x) by an mth
order polynomial.
mmm xaxaxaaxp ...)( 2
210
10
February 7, 2012 OSU/CSE 541 19
• The m’s (order of the polynomials) may be the same or different.
• Different choices for m’s lead to different formulas:
1 1 2
1
0 0
1 20 0 0
( ) ( ) ( ) ... ( )n m m m n
nm n mn
x x x x
m m mx x x xf x dx p x dx p x dx p x dx
)(3/8 sSimpson'cubic3
)(1/3 sSimpson'quadratic2
)(Trapezoidlinear1
ErrorFormulaPolynomial
4
4
2
hO
hO
hO
m
Newton-Cotes Formulas
February 7, 2012 OSU/CSE 541 20
• Simplest way to approximate the area under a curve – using first order polynomial (a straight line)
• Using Newton’s form of the interpolating polynomial:
• Now, solve for the integral:
b
a
b
adxxpdxxfI 1
axab
afbfafxp
1
Trapezoid Rule
11
February 7, 2012 OSU/CSE 541 21
Trapezoid Rule
b
adxax
ab
afbfafI
bfafab
I
2
a b
f(a)f(b)
height average width I
Trapezoid Rule
February 7, 2012 OSU/CSE 541 22
Trapezoid Rule
• Improvement?
x0 x1 x2 x4x3
12
February 7, 2012 OSU/CSE 541 23
• The integration error is:
• Where h = b - a and is an unknown point where a < < b (intermediate value theorem)
• You get exact integration if the function, f, is linear (f = 0)
23
12
)(
12
1hf
abhfEt
)( 3hO
Trapezoid Rule Error
February 7, 2012 OSU/CSE 541 24
2
)( xexf Integrate from a = 0 to b = 2
0183.1)(1
)0()2(2
)02(
2
04
2
0
2
ee
ffbfafab
dxeI x
Use trapezoidal rule:
Example
13
February 7, 2012 OSU/CSE 541 25
Estimate error: 3
12
1hfEt
Where h = b - a and a < < b
Don’t know - use average value2
)42()( 2 xexxf 2564.0)2(
2)0(
f
f
58.0
2
20
12
23
ff
EE at
202 h
Example
February 7, 2012 OSU/CSE 541 26
More intervals, better result [error O(h2)]
0
1
2
3
4
5
6
7
3 5 7 9 11 13 15
n = 2
0
1
2
3
4
5
6
7
3 5 7 9 11 13 15
n = 3
0
1
2
3
4
5
6
7
3 5 7 9 11 13 15
n = 4
0
1
2
3
4
5
6
7
3 5 7 9 11 13 15
n = 8
14
February 7, 2012 OSU/CSE 541 27
• If we do multiple intervals, we can avoid duplicate function evaluations and operations:
• Use n+1 equally spaced points.
• Each interval has:
• Break up the limits of integration and expand.n
abh
b
hb
ha
ha
ha
adxxfdxxfdxxfI ...
2
Composite Trapezoid Rule
February 7, 2012 OSU/CSE 541 28
• Substituting the trapezoid rule for each integral.
• Results in the Composite Trapezoid Formula:
2
22
2 2
....2
...a h a h b
a a h b h
a h a a h a hf a f a h f a h f a h
b b hf b h f b
I f x dx f x dx f x dx
bfihafafh
In
i
1
1
22
Composite Trapezoid Rule
15
February 7, 2012 OSU/CSE 541 29
n
bfihafafab
bfihafafh
I
n
i
n
i
2
2
22
1
1
1
1
width
Average height
Composite Trapezoid Rule
• Think of this as the width times the average height.
February 7, 2012 OSU/CSE 541 30
• The error can be estimated as:
• Where, is the average second derivative.
• If n is doubled, h h/2 and Ea Ea/4
• Note, that the error is dependent upon the width of the area being integrated.
f
n
abf
habEa
2
32
1212
f
)( 2hO
Error
16
February 7, 2012 OSU/CSE 541 31
0
5
10
15
20
25
30
35
40
0 0.2 0.4 0.6 0.8 1 1.2
Example
• Integrate:• from
a=0.2 to b=0.8
5432 200810730140203.0 xxxxxxf
February 7, 2012 OSU/CSE 541 32
26.112
81.322.342.08.0
2
bfafabI
Example
• A single application of the Trapezoid rule.
• Error: 3
12
1abfEt
17
February 7, 2012 OSU/CSE 541 33
Example
• We don’t know so approximate with average f
32 400097204380280 xxxxf
432 10003240219028020 xxxxxf
6.1312.08.0
)2.0()8.0(
2.08.0
8.0
2.0
ff
dxfxf
February 7, 2012 OSU/CSE 541 34
32
2
3
12 121
131.6 0.8 0.2 2.3712
t
b a h b aE f f
n
Example
• The error can thus be estimated as:
18
February 7, 2012 OSU/CSE 541 35
0
5
10
15
20
25
30
35
40
0 0.2 0.4 0.6 0.8 1 1.2
True value of integral is 12.82. Trapezoid rule is 11.26 - within approx error - Et is 12%
February 7, 2012 OSU/CSE 541 36
• Use intervals (0.2,0.4),(0.4,0.6),(0.6,0.8):– (n = 3, h = 0.2)
57.12 6
22.3416.3093.13231.36.0
)3)(2(
8.06.04.022.02.08.0
2
21
1
ffffn
bfihafafabI
n
i
True value of integral is 12.82
Using Three Intervals
19
February 7, 2012 OSU/CSE 541 37
0
5
10
15
20
25
30
35
40
0 0.2 0.4 0.6 0.8 1 1.2
Et is now 2%
February 7, 2012 OSU/CSE 541 38
76.12 12
22.3422.3516.3018.2293.1334.7231.36.0
)6)(2(
8.07.06.05.04.03.022.02.08.0
fffffffI
Using Six Intervals
• Use intervals (0.2,0.3),(0.3,0,4), etc. – (n = 6, h = 0.1)
True value of integral is 12.82
20
February 7, 2012 OSU/CSE 541 39
0
5
10
15
20
25
30
35
40
0 0.2 0.4 0.6 0.8 1 1.2
Et is now 0.5%
February 7, 2012 OSU/CSE 541 40
Multi-dimensional Integration
• Consider a two-dimensional case.
1 1 1
00 0 0
1
0 0
0 0
0 0
, ,
,
,
,
n
ii
n
ii
n n
i ji j
n n
i ji j
if x y dxdy A f y dy
n
iA f y dy
n
i jA A f
n n
i jA A f
n n
21
February 7, 2012 OSU/CSE 541 41
Multi-dimensional Integration
• For the Trapezoid Rule, this leads to weights in the following pattern:
1 2 2 2 2 2 1
2 4 4 4 4 4 2
2 4 4 4 4 4 2
2 4 4 4 4 4 2
2 4 4 4 4 4 2
2 4 4 4 4 4 2
1 2 2 2 2 2 1
2
1 0, 0,
2 1, , 2 1, 112 {1, 1} 1, , 14
4 1, , 2 1, , 2
ij
i n j n
i n j nA
i n j nn
i n j n
1
2
2
2
2
2
1
1 2 2 2 2 2 1
February 7, 2012 OSU/CSE 541 42
Multi-dimensional Integration
• If we use the weights from the Trapezoid rule, the error is still O(h2).
• However, there are now n2 function evaluations.– Equally-spaced samples on a square region.
22
February 7, 2012 OSU/CSE 541 43
Multi-dimensional Integration
• In general, given k dimensions, we have N= nk function evaluations:
• If the dimension is high, this leads to a significant amount of additional work in going from hh/2.– Remember this for Monte-Carlo Integration.
22
2 2 k kkO h O n O n O N
February 7, 2012 OSU/CSE 541 44
Reducing the Error
• To improve the estimate of the integral, we can either:– Add more intervals
– Use a higher order polynomial
– Use Richardson Extrapolation to examine the limit as h0.
• Called Romberg Integration
23
February 7, 2012 OSU/CSE 541 45
Adding More Intervals
• If we have an estimate for one value of h, do we need to recompute everything for a value of h/2?
1
1
22
n
hi
hI f a f a ih f b
February 7, 2012 OSU/CSE 541 46
Adding More Intervals
• This is called the Recursive Trapezoid Rule in the book.
• We have n 2n and hh/2.
2 1
12
1 1
1 0
1
0
( ) 2 ( )4 2
( ) 2 2 ( )4 2
22 4 2
n
hi
n n
i i
nh
i
h hI f a f a i f b
h hf a f a ih f a ih f b
I h hf a ih
24
February 7, 2012 OSU/CSE 541 47
• Given two numerical estimates obtained using different h’s, compute higher-order estimate
• Starting with a step size h1, the exact value is
• Suppose we reduce step size to h2
)()( 11nhOhAA
)()( 22nhOhAA
Recall Richardson Extrapolation
February 7, 2012 OSU/CSE 541 48
• Multiplying the 2nd eqn by (h1/h2)n and
subtracting from the 1st eqn:
• The new error term is generally O(h1n+1) or
O(h1n+2).
1
)()(
2
1
122
1
n
n
hh
hAhAhh
A
Richardson Extrapolation
25
February 7, 2012 OSU/CSE 541 49
• The true integral value can be written
• This is true for any iteration
Richardson Extrapolation
hEhII
2211 hEhIhEhII
February 7, 2012 OSU/CSE 541 50
Richardson Extrapolation
• For example: Using (n = 2)
• where c is a constant
• Therefore: 2
2
21
2
1
h
h
hE
hE
fchE 2 [error = O(h2)]
order of error in trapezoidal rule
26
February 7, 2012 OSU/CSE 541 51
• This leads to:
• For integration, we have:
22
21
21h
hhEhE
2222
21
21 hEhIh
hhEhI
Richardson Extrapolation
February 7, 2012 OSU/CSE 541 52
Richardson Extrapolation
• Solving for E(h2):
• And plugging back into the estimated integral.
22
21
212
1h
h
hIhIhE
22 hEhII
27
February 7, 2012 OSU/CSE 541 53
• Leads to:
• Letting h2 = h1 /2
Richardson Extrapolation
12221
21/
1hIhI
hhhII
12
1222
3
1
3
412
1
hIhII
hIhIhII
February 7, 2012 OSU/CSE 541 54
• We combined two O(h2) estimates to get an O(h4) estimate.
• Can also combine two O(h4) estimates to get an O(h6) estimate.
lm hIhII15
1
15
16
Romberg Integration
28
February 7, 2012 OSU/CSE 541 55
Romberg Integration
• Greater weight is placed on the more accurate estimate.
• Weighting coefficients sum to unity– i.e, (16-1)/15=1
• Can continue, by combining two O(h6) estimates to get an O(h8) estimate.
lm hIhII63
1
63
64
February 7, 2012 OSU/CSE 541 56
• General pattern is called Romberg Integration
– j : level of subdivision, j+1 has more intervals.
– k : level of integration, k = 1 is original trapezoid estimate [O(h2)], k = 2 is improved [O(h4)], etc.
, 1,, 1 , , 1,
4 1
4 1 4 1
kj k j k
j k j k j k j kk k
I II I I I
Romberg Integration
29
February 7, 2012 OSU/CSE 541 57
Romberg Integration
• For example, j = 1, k = 1 leads to
1,0 0,0 11,1 1
4 4 1
3 3 2 3
I I hI I I h
February 7, 2012 OSU/CSE 541 58
• Consider the function:
• Integrate from a = 0 to b = 0.8
• Using the trapezoidal rule yields the following results:
5432 400900675200252.0)( xxxxxxf
Example
30
February 7, 2012 OSU/CSE 541 59
intervals Integral
1 0.8 0.1728
2 0.4 1.0688
4 0.2 1.4848
h
Example
• Trapezoid Rules:
Exact integral is 1.64053334
3674667.1)1728.0(3
1)0688.1(
3
4I (j=1, k=1)
k
j
k = 0 k = 1
j = 0
j = 1
j = 2
February 7, 2012 OSU/CSE 541 60
2 4segments ( ) ( )
1 0.8 0.1728
2 0.4 1.0688 1.3674667
4 0.2 1.4848
h O h O hk
j
62346667.1)0688.1(3
1)4848.1(
3
4I (j=2, k=1)
k = 1k = 0
Exact integral is 1.64053334
Example
31
February 7, 2012 OSU/CSE 541 61
Example
2 4segments ( ) ( )
1 0.8 0.1728
2 0.4 1.0688 1.3674667
4 0.2 1.4848 1.62346667
h O h O hk
j
(j=2, k=2)
k = 2k = 1
Exact integral is 1.64053334
64053334.1)3674667.1(15
1)62346667.1(
15
16I
February 7, 2012 OSU/CSE 541 62
2 4 6segments ( ) ( ) ( )
1 0.8 0.1728
2 0.4 1.0688 1.3674667
4 0.2 1.
h O h O h O h
4848 1.62346667 1.64053334
k
jk = 3k = 2k = 1
Example
32
February 7, 2012 OSU/CSE 541 63
2 4 6 8segments ( ) ( ) ( ) ( )
1 0.8 0.1728
2 0.4 1.0688 1.3674667
4
h O h O h O h O h
0.2 1.4848 1.62346667 1.64053334
8 0.1 ?? ?? ?? ??
??)64053334.1(63
1(??)
63
64I (j=3, k=3)
k
j
k = 3
Example
• Better and better results can be obtained by continuing this
February 7, 2012 OSU/CSE 541 64
Romberg Integration
• Is this that significant?• Consider the cost of computing the
Trapezoid Rule for 1000 data points.– Refinement would lead to 2000 data points.
• Implies an additional 1003 operations using the Recursive Trapezoid Rule.
• Not to mention the 1000 (expensive) function evals.
– Romberg Integration cost:• Three additional operations – no function evals!!!
33
February 7, 2012 OSU/CSE 541 65
Higher-Order Polynomials
• Recall:
)(3/8 sSimpson'cubic3
)(1/3 sSimpson'quadratic2
)(Trapezoidlinear1
ErrorFormulaPolynomial
4
4
2
hO
hO
hO
m
1 1 2
1
0 0
1 20 0 0
( ) ( ) ( ) ... ( )n m m m n
nm n mn
x x x x
m m mx x x xf x dx p x dx p x dx p x dx
February 7, 2012 OSU/CSE 541 66
• If we use a 2nd order polynomial (need 3 points or 2 intervals):– Lagrange form.
dxxf
xxxx
xxxx
xfxxxx
xxxxxf
xxxx
xxxxI
x
x
21202
10
12101
200
2010
212
0
2
201
xxx
Simpson’s 1/3 Rule
34
February 7, 2012 OSU/CSE 541 67
Simpson’s 1/3 Rule
• Requiring equally-spaced intervals:
2
0
0 0 0 00 1
0 02
2 2
2
2
x
x
x x h x x h x x x x hI f x f x
h h h h
x x x x hf x dx
h h
February 7, 2012 OSU/CSE 541 68
• Integrate and simplify:
0
2
4
6
8
10
12
3 5 7 9 11 13 15
210 43
xfxfxfh
I 2
abh
Simpson’s 1/3 Rule
QuadraticPolynomial
35
February 7, 2012 OSU/CSE 541 69
• If we use a = x0 and b = x2, and x1 = (b+a)/2
Simpson’s 1/3 Rule
6
4 210 xfxfxfabI
widthaverage height
February 7, 2012 OSU/CSE 541 70
• Error for Simpson’s 1/3 rule
Integrates a cubic exactly: 04 f
45
45
288090f
abf
hEt
2
abh
)( 5hO
Simpson’s 1/3 Rule
36
February 7, 2012 OSU/CSE 541 71
Composite Simpson’s 1/3 Rule
• As with Trapezoidal rule, can use multiple applications of Simpson’s 1/3 rule.
• Need even number of intervals– An odd number of points are required.
February 7, 2012 OSU/CSE 541 72
Composite Simpson’s 1/3 Rule
• Example: 9 points, 4 intervals
-5
0
5
10
15
20
25
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
37
February 7, 2012 OSU/CSE 541 73
• As in composite trapezoid, break integral up into n/2 sub-integrals:
• Substitute Simpson’s 1/3 rule for each integral and collect terms.
Composite Simpson’s 1/3 Rule
n
n
x
x
x
x
x
xdxxfdxxfdxxfI
2
4
2
2
0
...
1 2
01,3,5 2,4,6
4 2
3
n n
i j ni j
f x f x f x f x
I b an
n+1 data points, an odd number
February 7, 2012 OSU/CSE 541 74
• Odd coefficients receive a weight of 4, even receive a weight of 2.
• Doesn’t seem very fair, does it?
coefficients on numerator
14 1
1 41
14 1
i = 0
i = n
Composite Simpson’s 1/3 Rule
38
February 7, 2012 OSU/CSE 541 75
• The error can be estimated by:
• If n is doubled, h h/2 and Ea Ea/16
)4(4
)4(5
180180f
habf
nhEa
)4(f is the average 4th derivative
)( 4hO
Error Estimate
February 7, 2012 OSU/CSE 541 76
• Integrate from a = 0 to b = 2.
• Use Simpson’s 1/3 rule:
22
0 1 20
0 1 4
1 4 ( )
31
0 4 (1) 23
1 ( 4 ) 0.82994
3
xI e dx h f x f x f x
f f f
e e e
2
)( xexf
2 12
0 12 210
bx
baxax
abh
Example
39
February 7, 2012 OSU/CSE 541 77
• Error estimate:
• Where h = b - a and a < < b
• Don’t know – use average value
45
90f
hEt
4 4 4
5 50 1 241 1
90 90 3t a
f x f x f xE E f
Example
February 7, 2012 OSU/CSE 541 78
• Let’s look at the polynomial again:
– From a = 0 to b = 0.8
5432 400900675200252.0)( xxxxxxf
8.0 4.02
0 4.02 210
bx
baxax
abh
36746667.1
8.0)4.0(403
)4.0(
)(43
1 )( 210
2
0
fff
xfxfxfhdxxfI
Exact integral is 1.64053334
Another Example
40
February 7, 2012 OSU/CSE 541 79
• Actual Error: (using the known exact value)
• Estimate error: (if the exact value is not available)
• Where a < < b.
45
90f
hEt
27306666.036746667.1-1.64053334 E 16%
Error
February 7, 2012 OSU/CSE 541 80
• Compute the fourth-derivative
• Matches actual error pretty well.
Error
xxf 4800021600)()4(
27306667.04.090
4.0
90
4.0 45
14
5
fxfEE at
middle point
41
February 7, 2012 OSU/CSE 541 81
• If we use 4 segments instead of 1:– x = [0.0 0.2 0.4 0.6 0.8]
0.2b a
hn
232.0)8.0( 464.3)6.0(
456.2)4.0( 288.1)2.0( 2.0)0(
ff
fff
6234667.1 12
232.0)456.2(2)464.3288.1(42.08.0
)4)(3(
)8.0()6.0(4)4.0(2)2.0(4)0(08.0
3
241
5,3,1
2
6,4,20
fffffn
xfxfxfxf
abIn
n
i
n
jji
Exact integral is 1.64053334
Example Continued
February 7, 2012 OSU/CSE 541 82
• Actual Error: (using the known exact value)
• Estimate error: (if the exact value is not available)
01706667.06234667.1-1.64053334 E 1%
0085.04.090
2.0
90
2.0 45
24
5
fxfEE at
middle point
Error
42
February 7, 2012 OSU/CSE 541 83
Error
• Actual is twice the estimated, why?
• Recall:xxf 4800021600)()4(
( 4 ) ( 4 )
0 , 0 . 8
( 4 )
m a x ( ) ( 0 ) 2 1 6 0 0
( 0 . 4 ) 2 4 0 0
xf x f
f
February 7, 2012 OSU/CSE 541 84
Error
• Rather than estimate, we can bound the absolute value of the error:
• Five times the actual, but provides a safer error metric.
5 5
4 40.2 0.20 0.0768
90 90aE f f
43
February 7, 2012 OSU/CSE 541 85
Simpon’s 1/3 Rule
• Simpson’s 1/3 rule uses a 2nd order polynomial– need 3 points or 2 intervals
– This implies we need an even number of intervals.
• What if you don’t have an even number of intervals? Two choices:1. Use Simpson’s 1/3 on all the segments except the last
(or first) one, and use trapezoidal rule on the one left.– Pitfall - larger error on the segment using trapezoid
2. Use Simpson’s 3/8 rule.
February 7, 2012 OSU/CSE 541 86
• Simpson’s 3/8 rule uses a third order polynomial– need 3 intervals (4 data points)
33
22103 )()( xaxaxaaxpxf
3
0
3
03
x
x
x
xdxxpdxxfI
Simpson’s 3/8 Rule
44
February 7, 2012 OSU/CSE 541 87
Simpson’s 3/8 Rule
• Determine a’s with Lagrange polynomial
• For evenly spaced points
3
abh
3210 338
3xfxfxxfhI
February 7, 2012 OSU/CSE 541 88
• Same order as 1/3 Rule.– More function evaluations.
– Interval width, h, is smaller.
• Integrates a cubic exactly:
04 f
453
80tE h f )( 4hO
Error
45
February 7, 2012 OSU/CSE 541 89
Comparison
• Simpson’s 1/3 rule and Simpson’s 3/8 rule have the same order of error– O(h4)– trapezoidal rule has an error of O(h2)
• Simpson’s 1/3 rule requires even number of segments.
• Simpson’s 3/8 rule requires multiples of three segments.
• Both Simpson’s methods require evenly spaceddata points
February 7, 2012 OSU/CSE 541 90
• n = 10 points 9 intervals– First 6 intervals - Simpson’s 1/3
– Last 3 intervals - Simpson’s 3/8
Simpson’s 1/3
Simpson’s 3/8
Mixing Techniques
46
February 7, 2012 OSU/CSE 541 91
• We can examine even higher-order polynomials.– Simpson’s 1/3 - 2nd order Lagrange (3 pts)
– Simpson’s 3/8 - 3rd order Lagrange (4 pts)
• Usually do not go higher.
• Use multiple segments.– But only where needed.
Newton-Cotes Formulas
February 7, 2012 OSU/CSE 541 92
Adaptive Simpson’s Scheme
• Recall Simpson’s 1/3 Rule:
• Where initially, we have a=x0 and b=x2.
• Subdividing the integral into two:
210 43
xfxfxfh
I
1 2 34 2 46
hI f a f x f x f x f b
47
February 7, 2012 OSU/CSE 541 93
Adaptive Simpson’s Scheme
• We want to keep subdividing, until we reach a desired error tolerance, .
• Mathematically:
1
1 2 3
43
4 2 46
b
a
b
a
hf x dx f a f x f b
hf x dx f a f x f x f x f b
February 7, 2012 OSU/CSE 541 94
Adaptive Simpson’s Scheme
• This will be satisfied if:
• The left and the right are within one-half of the error.
1 2
2 3
2
4 ,6 2
4 ,6 2
2
c
a
b
c
hf x dx f a f x f x and
hf x dx f x f x f b where
a bc x
48
February 7, 2012 OSU/CSE 541 95
Adaptive Simpson’s Scheme
• Okay, now we have two separate intervals to integrate.
• What if one can be solved accurately with an h=10-3, but the other requires many, many more intervals, h=10-6?
February 7, 2012 OSU/CSE 541 96
Adaptive Simpson’s Scheme
• Adaptive Simpson’s method provides a divide and conquer scheme until the appropriate error is satisfied everywhere.
• Very popular method in practice.
• Problem:– We do not know the exact value, and hence do
not know the error.
49
February 7, 2012 OSU/CSE 541 97
Adaptive Simpson’s Scheme
• How do we know whether to continue to subdivide or terminate?
5
4
, , ,
, 4 ,6 2
1,
90 2
b
a
I f x dx S a b E a b where
b a a bS a b f a f f b and
b aE a b f
February 7, 2012 OSU/CSE 541 98
Adaptive Simpson’s Scheme
• The first iteration can then be defined as:
• Subsequent subdivision can be defined as: 2 , ,S S a c S c b
1 1
1 1
,
, , ,
I S E where
S S a b E E a b
50
February 7, 2012 OSU/CSE 541 99
Adaptive Simpson’s Scheme
• Now, since
• We can solve for E(2) in terms of E(1).
5 52 4 4
54 1
4
1 / 2 1 / 2
90 2 90 2
1 1 1
2 90 2 16
h hE f f
hf E
2 , ,E E a c E c b
February 7, 2012 OSU/CSE 541 100
Adaptive Simpson’s Scheme
• Finally, using the identity:
• We have:
• Plugging into our definition:
1 1 2 2I S E S E
2 1 1 2 215S S E E E
2 2 2 2 11
15I S E S S S
51
February 7, 2012 OSU/CSE 541 101
Adaptive Simpson’s Scheme
• Our error criteria is thus:
• Simplifying leads to the termination formula:
2 2 11
15I S S S
2 1 15S S
February 7, 2012 OSU/CSE 541 102
Adaptive Simpson’s Scheme
• What happens graphically:
52
February 7, 2012 OSU/CSE 541 103
12 15S subd vS i ide
February 7, 2012 OSU/CSE 541 104
53
February 7, 2012 OSU/CSE 541 105
12 152
subdivideSS
February 7, 2012 OSU/CSE 541 106
2 12
1
15SI S S
12 154
S oS d ne
54
February 7, 2012 OSU/CSE 541 107
12 154
subdivideSS
February 7, 2012 OSU/CSE 541 108
2 12
1
15SI S S
55
February 7, 2012 OSU/CSE 541 109
2 12
1
15SI S S
February 7, 2012 OSU/CSE 541 110
I=Ileft + Iright
Iright =Ileft + Iright
56
February 7, 2012 OSU/CSE 541 111
February 7, 2012 OSU/CSE 541 112
57
February 7, 2012 OSU/CSE 541 113
Adaptive Simpson’s Scheme
• We gradually capture the difficult spots.
February 7, 2012 OSU/CSE 541 114
Adaptive Simpson’s Code
• Simple Recursive Programstatic const int m_nMaximum_Divisions = 1000;Real IntegrationSimpson( const Real (*f) (Real x), const Real start, const Real end, const Real
error_tolerance, int &level ){
level += 1;Real h = (end – start);Real midpoint = (start + end) / 2.0;Real f_start = f(start);Real f_end = f(end);Real f_mid = f(midpoint );oneLevel = h*( f_start + 4.0*f_mid + f_end) / 6.0;Real leftMidpoint = (start+ midpoint ) / 2.0;Real rightMidpoint = (end+ midpoint ) / 2.0Real f_midLeft = f(leftMidpoint );Real f_midRight = f(rightMidpoint );twoLevel = h*(f_start + 4.0* f_midLeft + 2.0* f_mid + 4.0* f_midRight + f_end) / 12.0;if( level >= m_nMax_Divisions ) // Terminate the process, converging too slow
return twoLevel;
58
February 7, 2012 OSU/CSE 541 115
Adaptive Simpson’s Code
if( absf( twoLevel – oneLevel) < 15.0*error_tolerance) // Desired solution reachedreturn twoLevel + (twoLevel-oneLevel) / 15.0;
//// Otherwise, split the interval in two and recursively evaluate each half.//leftIntegral = IntegrationSimpson( f, start, midpoint , error_tolerance/2.0, level );rightIntegral = IntegrationSimpson( f, midpoint , end, error_tolerance/2.0, level );return leftIntegral + rightIntegral;
}
February 7, 2012 OSU/CSE 541 116
• Idea is that if we evaluate the function at certain points, and sum with certain weights, we will get a more accurate integral
• Evaluation points and weights are pre-computed and tabulated
• Basic form:
1
11
)()(n
iii xfcdxxfI
ci : weighting factorsxi : sampling points selected optimally
Guassian Quadrature
New!!
59
February 7, 2012 OSU/CSE 541 117
• Note that the interval is between –1 and 1
• For other intervals, a change of variables is used to transfer the problem so that it utilizes the interval [-1, 1]
• This is a linear transform, such that for t[a,b]:
• We have for x[-1,1]:
b
adttf )(
2
)( abxabt
ab
abtx
2
Guassian Quadrature
February 7, 2012 OSU/CSE 541 118
• As t = a x = -1
• As t = b x = 1
dxab
dt2
)(
2
)()(
abxabftf
dxabxab
fab
dttfb
a
1
1 2
)(
2
)()(
Guassian Quadrature
60
February 7, 2012 OSU/CSE 541 119
• Basic form of Gaussian quadrature:
• For n=2, we have:
• This leads to 4 unknowns: c1, c2, x1, and x2
– two unknown weights (c1, c2)– two unknown sampling points (x1, x2)
1
11
)()(n
iii xfcdxxfI
2211 xfcxfcI
Guassian Quadrature
February 7, 2012 OSU/CSE 541 120
Guassian Quadrature
• What we need now, are four known values for the equation.
• If we had these, we could then attempt to solve for the four unknowns.
• Let’s make it work for polynomials!!!
61
February 7, 2012 OSU/CSE 541 121
• In particular, let’s look at these simple polynomials: – Constant
• f(x)=1
– Linear• f(x)=x
– Quadratic• f(x)=x2
– Cubic• f(x)=x3
Guassian Quadrature
February 7, 2012 OSU/CSE 541 122
Guassian Quadrature
• Recalling the formula: – Constant
• f(x)=1
– Linear• f(x)=x
– Quadratic• f(x)=x2
– Cubic• f(x)=x3
322
3112211
1
1
3
222
2112211
1
1
2
22112211
1
1
212211
1
1
0
3
2
0
21
xcxcxfcxfcdxx
xcxcxfcxfcdxx
xcxcxfcxfcxdx
ccxfcxfcdx
2211 xfcxfcI
62
February 7, 2012 OSU/CSE 541 123
• We can now solve for our unknowns:– Note, this is not an easy problem and will not be
covered in this class.
577.03
1
577.03
1
1
2
1
21
x
x
cc
Guassian Quadrature
February 7, 2012 OSU/CSE 541 124
Guassian Quadrature
• This yields the two point Gauss-Legendreformula
3
1
3
1ffI
63
February 7, 2012 OSU/CSE 541 125
Guassian Quadrature
• This is exact for all polynomials up to and including degree 3 (cubics).
1 1 1 1 13 2 3 2
1 1 1 1 1
3 3 2 2
1
3
1
3
1 1 1 1 1 11 1
3 3 3 3 3 3
3 2
ax bx cx d dx a x dx b x dx c xdx d dx
a b c d
ax bx cx d
February 7, 2012 OSU/CSE 541 126
x
f(x)
-1 1
f(0.577)f(-0.577)
-0.577 0.577
1
1)577.0()577.0()( ffdxxf
Guassian Quadrature
64
February 7, 2012 OSU/CSE 541 127
Example
5432 400900675200252.0)( xxxxxxf
dxabxab
fab
dttfb
a
1
1 2
)(
2
)()(
dttf
dtt
fdxxfI
1
1
1
1
8.0
0
4.04.04.0
2
08.0)08.0(
2
)08.0()(
• Integrate f(x) from a = 0 to b = 0.8
• Transform from [0, 0.8] to [-1, 1]
February 7, 2012 OSU/CSE 541 128
• Solving
• And substituting for the 2-point formula:
Exact integral is 1.64053334
dtttt
tt
dttfI
1
1 543
2
1
1
)4.04.0(400)4.04.0(900)4.04.0(675
)4.04.0(200)4.04.0(252.04.0
4.04.04.0
3/1t
82257778.130583723.151674055.0 I
dttfI 1
14.0
Example
65
February 7, 2012 OSU/CSE 541 129
• Recall the basic form:
• Let’s look at n=3.
• We now have 6 unknowns: c1, c2, c3,x1, x2, and x3– three unknown weights (c1, c2 , c3)– three unknown sampling points (x1, x2 , x3)
1
11
)()(n
iii xfcdxxfI
332211 xfcxfcxfcI
Higher-order Gaussian Quadrature
February 7, 2012 OSU/CSE 541 130
Use 6 equations - constant, linear, quadratic, cubic, 4th order and 5th order to find those unknowns
533
522
511332211
1
1
5
433
422
411332211
1
1
4
333
322
311332211
1
1
3
233
222
211332211
1
1
2
332211332211
1
1
321332211
1
1
0
5
2
0
3
2
0
21
xcxcxcxfcxfcxfcdxx
xcxcxcxfcxfcxfcdxx
xcxcxcxfcxfcxfcdxx
xcxcxcxfcxfcxfcdxx
xcxcxcxfcxfcxfcxdx
cccxfcxfcxfcdx
66
February 7, 2012 OSU/CSE 541 131
• Can solve these equations (or have some one smarter than us, like Guass solve them).
• Produces the three point Gauss-Legendre formula
– Exact for polynomials up to and including degree 5(because using 5th degree polynomial)
77459669.05/3 0 77459669.05/3
9/5 9/8 9/5
221
321
xxx
ccc
332211 xfcxfcxfcI
Higher-order Gaussian Quadrature
February 7, 2012 OSU/CSE 541 132
1
1)775.0(
9
5)0.0(
9
8)775.0(
9
5)( fffdxxf
-1 1x
f(0.775)
f(-0.775)
-0.775 0.775
f(0)
Higher-order Gaussian Quadrature
67
February 7, 2012 OSU/CSE 541 133
5432 400900675200252.0)( xxxxxxf
Integrate from a = 0 to b = 0.8
Transform from [0, 0.8] to [-1, 1]
dtttt
tt
dxxfI
1
1 543
2
8.0
0
)4.04.0(400)4.04.0(900)4.04.0(675
)4.04.0(200)4.04.0(252.0
Example
replace -0.4 with +0.4
February 7, 2012 OSU/CSE 541 134
5
3
9
50
9
8
5
3
9
5fffI
64053334.1
485987599.0873244444.0281301290.0
I
Substitute into the transform equation and get
Exact integral is 1.64053334
Example
• Using the 3-point Gauss-Legendre formula:
68
February 7, 2012 OSU/CSE 541 135
Can develop higher order Gauss-Legendre forms using
nn xfcxfcxfcI ...2211
Values for c’s and x’s are tabulated
Use the same transformation to map interval onto [-1, 1]
Gaussian Quadrature
February 7, 2012 OSU/CSE 541 136
1713245.0
3607616.0
4679139.0
4679139.0
3607616.0
1713245.0
500.23692688
050.47862867
890.56888888
050.47862867
500.23692688
510.34785484
490.65214515
490.65214515
510.34785484
560.55555555
890.88888888
560.55555555
0.1
0.1
9324695140
6612093860
2386191860
2386191860
6612093860
9324695140
90617984590
53846931010
00000000000
53846931010
90617984590
86113631160
33998104360
33998104360
86113631160
77459666920
00000000000
77459666920
57735026920
57735026920
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2 3 4 5 6nci
xi
nn xfcxfcxfcdxxfI ...)( 2211
1
1
69
February 7, 2012 OSU/CSE 541 137
Gaussian Quadrature
• Requires function evaluations at non-uniformly spaced points within the integration interval– not appropriate for cases where the function is
unknown– not suited for dealing with tabulated data that
appear in many engineering problems
• If the function is known, its efficiency can be a decided advantage
February 7, 2012 OSU/CSE 541 138
Gaussian Quadrature
• Problems:– If we add more data points, like doubling the
number of sample points.
top related