Upload
ernest-boyd
View
231
Download
0
Tags:
Embed Size (px)
Citation preview
Numerical Computation
Lecture 16: Numerical Integration
United International College
Last Time
• During the last class period we covered:– Numerical Approximations to Derivatives– Readings: • Pav, Chapter 7
Today
• We will cover:– Numerical Integration (Quadrature)– Readings: • Pav, Chapter 8, sections 8.1-8.3• Moler,
The Definite Integral
• The definite integral is the total value or
summation of f(x) over a range of x.
• The integration symbol is actually a stylized capital S intended to signify the connection between integration and summation.
b
a
dxxf )(
The Definite Integral
f(x)
x
I f x dxa
b
ba
Upper, Lower Sums
• We approximate the definite integral by splitting the interval from a to b into n subintervals a = x0 < x1 < x2 < . . . < xn-1 < xn = b
• This is called a partition P of [a,b]. • On each subinterval [xi-1 ,xi ] define the smallest value
of f(x) to be mi and the largest value of f(x) to be Mi . mi = min{ f(x) | xi-1 < x < xi }
Mi = max{ f(x) | xi-1 < x < xi }
Upper, Lower Sums
• Then, we can define Lower and Upper approximating sums for the integral: )(),(
)(),(
1
1
0
1
1
0
ii
n
ii
ii
n
ii
xxMPfU
xxmPfL
Upper, Lower Sums
• Definition: A function f(x) is Riemann-integrable over [a,b] if
over all possible partitions P. Here the words “sup” and “inf” can be thought of as the same as maximum and minimum.
• Theorem (from calculus): If f(x) is continuous on [a,b], then it is Riemann-integrable on [a,b]
),(inf),(sup PfUPfLPP
Upper, Lower Sums
• Note: While this is a good definition, in practice it is often hard to find the max and min of f(x) on each subinterval.
• Idea: Use a simpler approximation that is between the Upper and Lower approximations.
Simple Trapezoidal Rule
• Over a single interval [a,b] we can approximate f(x) by a line and find the area under this line. This area looks like a trapezoid.
Simple Trapezoidal Rule
• The area under this trapezoid is just
)(2
)()(ab
bfaf
Composite Trapezoidal Rule
• To get a better approximation for f(x) over [a,b] we create a partition with equal sized subintervals:
a = x0 < x1 < x2 < . . . < xn-1 < xn = b with the width of every subinterval = h. That is,
xi+1 - xi = h for all i. Adding up all the trapezoidal areas we get
1
01
1
0
))()((2
1)()(
1 n
iii
b
a
n
i
x
x
hxfxfdxxfdxxfi
i
Composite Trapezoidal Rule
• Factoring out the h we get
• This is the Composite Trapezoidal Rule
1
01))()((
2)(
n
iii
b
a
xfxfh
dxxf
Composite Trapezoidal Rule
• Example: Approximate using the composite trapezoidal rule with n=4. • Solution: h = (2-0)/4 = ½. Partition is 0 < 0.5 < 1.0 < 1.5 < 2.0 Trapezoidal Rule gives
2
02 1
1dx
x
))]0.2()5.1(())5.1()0.1((
))0.1()5.0(())5.0()0([(2
2/1
1
12
02
ffff
ffffdxx
1038.1
)]2.013
4()
13
45.0()5.08.0()8.01[(
4
1
1
12
02
dx
x
Error in Trapezoidal Rule
• Theorem: (Section 8.2.1 in Pav)
• Proof: (Read section 8.2.1 in Pav)• Note: The trapezoidal rule will be exact (no error) if
the function f(x) is linear. (Why?)
bawhere
fhab
E
''12
)( 2
Simple Midpoint Rule
• The area defined by a rectangle of height f((a+b)/2) is
))(2
( abba
f
a b(a+b)/2
Composite Midpoint Rule
• Create a partition: a = x0 < x1 < x2 < . . . < xn-1 < xn = b with the width of every subinterval = h. Adding up all
the midpoint areas we get
• This is the Composite Midpoint Rule
1
0
11
0
))2
(()()(1 n
i
iib
a
n
i
x
x
xxfhdxxfdxxf
i
i
Simple Simpson’s Rule
• Instead of using linear approximations to f(x), we can use a 2nd order Lagrange polynomial approximation L(x). To do this, we will need three points, a,b, and x1 halfway between a and b.
a=x0 c=x1
f(x)
b=x2
L(x)
Simple Simpson’s Rule
• The area under L(x) can be an approximation to the integral
2
0
21202
101
2101
200
2010
21
)()(
x
x
b
a
b
a
dxxfxxxx
xxxxxf
xxxx
xxxxxf
xxxx
xxxx
dxxLdxxf
Simple Simpson’s Rule
• After integrating and simplifying we get
210 46
)()( xfxfxf
abdxxf
b
a
Composite Simpson’s Rule
• Create a partition with an even number of subintervals: a = x0 < x1 < x2 < . . . < xn-1 < xn = b
with the width of every subinterval = h. On every pair of subintervals, [x0 , x1], [x1 , x2 ], etc, we use Simpson’s Rule:
x0 x2 x
f(x)
x4h h xn-2h xn
…...
hx3x1 xn-1
Composite Simpson’s Rule
• We get:
)()(4)(2
)4f(x)(2)f(x4
)2f(x)f(x4)2f(x)f(x4)f(x3
)f(x)4f(x)f(x6
2h
)f(x)f(x4)f(x6
2h)f(x)f(x4)f(x
6
2h
f(x)dxf(x)dxf(x)dxf(x)dx
12
12i21-2i
43210
n1n2n
432210
x
x
x
x
x
x
b
a
n
2n
4
2
2
0
nnn
i
xfxfxf
xf
h
Composite Simpson’s Rule
• Simplifying, we have
• This is the Composite Simpson’s Rule
• Note: The error in Simpson’s rule is O(h4)
]24[3
f(x)dx1
..5,3,1
2
..6,4,20
b
a
n
i
n
jnji xfxfxfxf
h
Matlab – Trapezoidal Rule
function sum = trapezoid( f, a, b, n )% trapezoid computes the trapezoidal rule% approximation to f(x) over [a,b] using n % equally spaced subintervalsh = (b-a)/n;x = a + (h .* (0:n)); % vector of partition x valuessum=0.0;for i = 1:n sum = sum + (h/2.0)*(f(x(i)) + f(x(i+1)));endend
Matlab – Trapezoidal Rule
>> trapezoid(inline('x^2'),1,2,64)ans = 2.3334
Romberg Integration
• Idea: Use the Richardson Extrapolation technique to improve integral approximations.
• Consider the Trapezoidal Rule using 2n subintervals of [a,b]. Then, h = (b-a)/ 2n and the approximation will be
• We know that this approximation has error O(h2). Thus,
12
01)()(
22
1)(
n
iiinxfxf
abn
...)()( 66
44
22 hahahadxxfn
b
a
Romberg Integration
• This is exactly the kind of expression we had for Richardson Extrapolation in Chapter 7. Let
...)()( 66
44
22 hahahadxxfn
b
a
14
)1,1()1,(4),(
m
m mnRmnRmnR
)()0,( nnR
Romberg Intergation
• Compute the table of values:
• This is called Romberg Integration
Romberg Intergation
• Example: Approximate The exact value =
dxxe x4
0
2
926477.5216
02.008.027.075.202.139
95.521601.521720.521768.521995.535525.0
84.522414.522975.525676.57645.0
68.549998.567079.72881
41.82402.121422
7.238474
43210
)()()()()( 108642
error
h
h
h
h
h
mmmmm
hOhOhOhOhO
Trapezoid
Romberg Intergation
• Note: In the column for m=1 we have
• If we calculate this out, we get exactly the Simpson’s Rule approximations for the integral.
3
)1()(4
3
)0,1()0,(4)1,(
nnnRnRnR
84.522414.522975.525676.57645.0
68.549998.567079.72881
41.82402.121422
7.238474
43210
)()()()()(
'108642
h
h
h
h
mmmmm
hOhOhOhOhO
sSimpsonTrapezoid