CISE301_Topic7 KFUPM 1
SE301: Numerical MethodsTopic 7
Numerical Integration Lecture 24-27
KFUPM
Read Chapter 21, Section 1Read Chapter 22, Sections 2-3
CISE301_Topic7 KFUPM 2
Lecture 24Introduction to
Numerical Integration
Definitions Upper and Lower Sums Trapezoid Method (Newton-Cotes Methods) Romberg Method Gauss Quadrature Examples
CISE301_Topic7 KFUPM 3
IntegrationIntegrationIndefinite Integrals
Indefinite Integrals of a function are functions that differ from each other by a constant.
cx
dxx2
2
Definite Integrals
Definite Integrals are numbers.
2
1
2
1
0
1
0
2
x
xdx
CISE301_Topic7 KFUPM 4
Fundamental Theorem of Fundamental Theorem of CalculusCalculus
:forsolution form closedNo
:for tiveantideriva no is There
) f(x)(x) 'F (i.e., f of tiveantideriva is
, intervalan on continuous is If
2
2
b
a
x
x
b
a
dxe
e
F(a)F(b)f(x)dx
F
[a,b]f
CISE301_Topic7 KFUPM 5
The Area Under the The Area Under the CurveCurve
b
af(x)dxArea
One interpretation of the definite integral is:
Integral = area under the curve
a b
f(x)
CISE301_Topic7 KFUPM 6
Upper and Lower SumsUpper and Lower Sums
a b
f(x)
3210 xxxx
ii
n
ii
ii
n
ii
iii
iii
n
xxMPfUsumUpper
xxmPfLsumLower
xxxxfM
xxxxfm
Define
bxxxxaPPartition
1
1
0
1
1
0
1
1
210
),(
),(
:)(max
:)(min
...
The interval is divided into subintervals.
CISE301_Topic7 KFUPM 7
Upper and Lower SumsUpper and Lower Sums
a b
f(x)
3210 xxxx
2
2 integral theof Estimate
),(
),(
1
1
0
1
1
0
LUError
UL
xxMPfUsumUpper
xxmPfLsumLower
ii
n
ii
ii
n
ii
CISE301_Topic7 KFUPM 8
ExampleExample
14
3
2
1
4
103,2,1,0
4
1
1,16
9,
4
1,
16
116
9,
4
1,
16
1,0
)intervals equalfour (4
1,4
3,
4
2,
4
1,0 :
1
3210
3210
1
0
2
iforxx
MMMM
mmmm
n
PPartition
dxx
ii
CISE301_Topic7 KFUPM 9
ExampleExample
14
3
2
1
4
10
8
1
64
14
64
30
2
1
32
11
64
14
64
30
2
1integraltheofEstimate
64
301
16
9
4
1
16
1
4
1),(
),(
64
14
16
9
4
1
16
10
4
1),(
),(
1
1
0
1
1
0
Error
PfU
xxMPfUsumUpper
PfL
xxmPfLsumLower
ii
n
ii
ii
n
ii
CISE301_Topic7 KFUPM 10
Upper and Lower SumsUpper and Lower Sums• Estimates based on Upper and Lower
Sums are easy to obtain for monotonic functions (always increasing or always decreasing).
• For non-monotonic functions, finding maximum and minimum of the function can be difficult and other methods can be more attractive.
CISE301_Topic7 KFUPM 11
Newton-Cotes Methods In Newton-Cote Methods, the function
is approximated by a polynomial of order n.
Computing the integral of a polynomial is easy.
1
)(...
2
)()()(
...)(
1122
10
10
n
aba
abaabadxxf
dxxaxaadxxf
nn
n
b
a
b
a
nn
b
a
CISE301_Topic7 KFUPM 12
Newton-Cotes Methods Trapezoid Method (First Order Polynomials are used)
Simpson 1/3 Rule (Second Order Polynomials are used)
b
a
b
a
b
a
b
a
dxxaxaadxxf
dxxaadxxf
2210
10
)(
)(
CISE301_Topic7 KFUPM 13
Lecture 25Trapezoid Method
Derivation-One Interval Multiple Application Rule Estimating the Error Recursive Trapezoid Method
Read 21.1
CISE301_Topic7 KFUPM 14
Trapezoid MethodTrapezoid Method
)()()(
)( axab
afbfaf
f(x)
ba 2
)()(
2
)()(
)()()(
)()()(
)(
)(
2
afbfab
x
ab
afbf
xab
afbfaaf
dxaxab
afbfafI
dxxfI
b
a
b
a
b
a
b
a
CISE301_Topic7 KFUPM 15
Trapezoid MethodDerivation-One Interval
2
)()(
)()(2
)()()()()(
2
)()()()()(
)()()()()(
)()()(
)()(
22
2
afbfab
abab
afbfab
ab
afbfaaf
x
ab
afbfx
ab
afbfaaf
dxxab
afbf
ab
afbfaafI
dxaxab
afbfafdxxfI
b
a
b
a
b
a
b
a
b
a
CISE301_Topic7 KFUPM 16
Trapezoid MethodTrapezoid Method
)(bf
f(x)
ba
)()(2
bfafab
Area
)(af
CISE301_Topic7 KFUPM 17
Trapezoid MethodTrapezoid MethodMultiple Application RuleMultiple Application Rule
a b
f(x)
3210 xxxx
s trapezoid theof
areas theof sum)(
...
segments into dpartitione
is b][a, intervalThe
210
b
a
n
dxxf
bxxxxa
n
1212
2
)()(xx
xfxfArea
x
CISE301_Topic7 KFUPM 18
Trapezoid MethodTrapezoid MethodGeneral Formula and Special CaseGeneral Formula and Special Case
)()(2
1)(
...
equal)y necessaril(not segments into divided is interval theIf
11
1
0
210
iiii
n
i
b
a
n
xfxfxxdxxf
bxxxxa
n
1
10
1
)()()(2
1)(
allfor
points) base spacedEqualiy ( CaseSpecial
n
iin
b
a
ii
xfxfxfhdxxf
ihxx
CISE301_Topic7 KFUPM 19
Example
Given a tabulated values of the velocity of an object.
Obtain an estimate of the distance traveled in the interval [0,3].
Time (s) 0.0 1.0 2.0 3.0
Velocity (m/s) 0.0 10 12 14
Distance = integral of the velocity
3
0)(Distance dttV
CISE301_Topic7 KFUPM 20
Example 1Example 1Time (s) 0.0 1.0 2.0 3.0
Velocity (m/s)
0.0 10 12 14
29)140(2
112)(101 Distance
)()(2
1)(
1
0
1
1
1
n
n
ii
ii
xfxfxfhT
xxh
MethodTrapezoid
3,2,1,0are points Base
lssubinterva3 into
divided is interval The
CISE301_Topic7 KFUPM 21
Estimating the Error Estimating the Error For Trapezoid MethodFor Trapezoid Method
?accuracy digit decimal 5 to
)sin( compute toneeded
are intervals spacedequally many How
0
dxx
CISE301_Topic7 KFUPM 22
Error in estimating the Error in estimating the integralintegralTheoremTheorem
)(''max12
)(12
then)( eapproximat
toused is Method Trapezoid If :Theorem
) (width intervals Equal
on continuous is)('' :Assumption
],[
2
''2
a
xfhab
Error
[a,b]wherefhab
Error
dxxf
h
[a,b]xf
bax
b
CISE301_Topic7 KFUPM 23
ExampleExample
52
52
],[
2
5
0
106
102
1
121)(''
)sin()('');cos()(';0;
)(''max12
102
1 error ,)sin(
h
hErrorxf
xxfxxfab
xfhab
Error
thatsohfinddxx
bax
CISE301_Topic7 KFUPM 24
ExampleExample
)()(2
1)(),(
, allfor :
)()(2
1),(
)(:compute tomethod Trapezoid Use
0
1
1
1
11
1
0
3
1
n
n
ii
ii
iiii
n
i
xfxfxfhPfT
ixxhCaseSpecial
xfxfxxPfTTrapezoid
dxxf
x 1.0 1.5 2.0 2.5 3.0
f(x) 2.1 3.2 3.4 2.8 2.7
CISE301_Topic7 KFUPM 25
ExampleExample
9.5
7.21.22
18.24.32.35.0
)()(2
1)()( 0
1
1
3
1
n
n
ii xfxfxfhdxxf
x 1.0 1.5 2.0 2.5 3.0
f(x) 2.1 3.2 3.4 2.8 2.7
CISE301_Topic7 KFUPM 26
Recursive Trapezoid Recursive Trapezoid MethodMethod
f(x)
haa
)()(2
)0,0(R
:interval oneon based Estimate
bfafab
abh
CISE301_Topic7 KFUPM 27
Recursive Trapezoid Recursive Trapezoid MethodMethod
f(x)
hahaa 2
)()0,0(2
1)0,1(
)()(2
1)(
2)0,1(R
2
:intervals 2on based Estimate
hafhRR
bfafhafab
abh
Based on previous estimate
Based on new point
CISE301_Topic7 KFUPM 28
Recursive Trapezoid Recursive Trapezoid MethodMethod
f(x)
)3()()0,1(2
1)0,2(
)()(2
1
)3()2()(4
)0,2(R
4
hafhafhRR
bfaf
hafhafhafab
abh
hahaa 42 Based on previous estimate
Based on new points
CISE301_Topic7 KFUPM 29
Recursive Trapezoid Recursive Trapezoid MethodMethodFormulasFormulas
n
k
abh
hkafhnRnR
bfafab
n
2
)12()0,1(2
1)0,(
)()(2
)0,0(R
)1(2
1
CISE301_Topic7 KFUPM 30
Recursive Trapezoid Recursive Trapezoid MethodMethod
)1(
2
2
1
2
13
2
12
1
1
)12()0,1(2
1)0,(,
2
..................
)12()0,2(2
1)0,3(,
2
)12()0,1(2
1)0,2(,
2
)12()0,0(2
1)0,1(,
2
)()(2
)0,0(R,
n
kn
k
k
k
hkafhnRnRab
h
hkafhRRab
h
hkafhRRab
h
hkafhRRab
h
bfafab
abh
CISE301_Topic7 KFUPM 31
Advantages of Recursive TrapezoidRecursive Trapezoid: Gives the same answer as the standard
Trapezoid method. Makes use of the available information to
reduce the computation time. Useful if the number of iterations is not
known in advance.
CISE301_Topic7 KFUPM 32
Lecture 26Romberg Method
Motivation Derivation of Romberg Method Romberg Method Example When to stop?
Read 22.2
CISE301_Topic7 KFUPM 33
Motivation for Romberg Motivation for Romberg MethodMethod
Trapezoid formula with an interval h gives an error of the order O(h2).
We can combine two Trapezoid estimates with intervals 2h and h to get a better estimate.
CISE301_Topic7 KFUPM 34
Romberg MethodRomberg Method
First column is obtained using Trapezoid Method
dx f(x) ofion approximat theimprove tocombined are
4h,8h,... 2h, h, size of intervals with method Trapezoid using Estimatesb
a
R(0,0)
R(1,0) R(1,1)
R(2,0) R(2,1) R(2,2)
R(3,0) R(3,1) R(3,2) R(3,3)The other elements are obtained using the Romberg Method
CISE301_Topic7 KFUPM 35
First Column First Column Recursive Trapezoid MethodRecursive Trapezoid Method
n
k
abh
hkafhnRnR
bfafab
n
2
)12()0,1(2
1)0,(
)()(2
)0,0(R
)1(2
1
CISE301_Topic7 KFUPM 36
Derivation of Romberg Derivation of Romberg MethodMethod
...)0,1()0,(3
1)0,()(
2*41
)2(...64
1
16
1
4
1)0,()(
R(n,0)by obtained is estimate accurate More
)1(...)0,1()(
2 method Trapezoid)()0,1()(
66
44
66
44
22
66
44
22
12
hbhbnRnRnRdxxf
giveseqeq
eqhahahanRdxxf
eqhahahanRdxxf
abhwithhOnRdxxf
b
a
b
a
b
a
n
b
a
CISE301_Topic7 KFUPM 37
Romberg MethodRomberg Method
1,1
)1,1()1,(14
1)1,(),(
)12()0,1(2
1)0,(
,2
)()(2
)0,0(R
)1(2
1
mnfor
mnRmnRmnRmnR
hkafhnRnR
abh
bfafab
m
k
n
n
R(0,0)
R(1,0) R(1,1)
R(2,0) R(2,1) R(2,2)
R(3,0) R(3,1) R(3,2) R(3,3)
CISE301_Topic7 KFUPM 38
Property of Romberg Property of Romberg MethodMethod
)(),()(
Theorem
22 mb
a
hOmnRdxxf
R(0,0)
R(1,0) R(1,1)
R(2,0) R(2,1) R(2,2)
R(3,0) R(3,1) R(3,2) R(3,3)
)()()()( 8642 hOhOhOhOError Level
CISE301_Topic7 KFUPM 39
Example 1Example 1
3
1
2
1
8
3
3
1
8
3)0,0()0,1(
14
1)0,1()1,1(
1,1
)1,1()1,(14
1)1,(),(
8
3
4
1
2
1
2
1
2
1))(()0,0(
2
1)0,1(,
2
1
5.0102
1)()(
2)0,0(,1
Compute
1
1
0
2
RRRR
mnfor
mnRmnRmnRmnR
hafhRRh
bfafab
Rh
dxx
m
0.5
3/8 1/3
CISE301_Topic7 KFUPM 40
Example 1 (cont.)Example 1 (cont.)
3
1
3
1
3
1
15
1
3
1)1,1()1,2(
14
1)1,2()2,2(
3
1
8
3
32
11
3
1
32
11)0,1()0,2(
14
1)0,1()1,2(
)1,1()1,(14
1)1,(),(
32
11
16
9
16
1
4
1
8
3
2
1))3()(()0,1(
2
1)0,2(,
4
1
2
1
RRRR
RRRR
mnRmnRmnRmnR
hafhafhRRh
m
0.5
3/8 1/3
11/32 1/3 1/3
CISE301_Topic7 KFUPM 41
When do we stop?When do we stop?
R(4,4)at STOP example,for
steps, ofnumber given aAfter
or
)1,(),( mnRmnR
ifSTOP
CISE301_Topic7 KFUPM 42
Lecture 27Gauss Quadrature
Motivation General integration formula
Read 22.3
CISE301_Topic7 KFUPM 43
MotivationMotivation
nandih
nihcwhere
xfcdxxf
xfxfxfhdxxf
i
n
iii
b
a
n
ini
b
a
05.0
1,...,2,1
)()(
:as expressed becan It
)()(2
1)()(
:Method Trapezoid
0
1
10
CISE301_Topic7 KFUPM 44
General Integration General Integration FormulaFormula
integral? theofion approximat good a gives
formula e that thsoselect wedo How
:Problem
::
)()(0
ii
ii
n
iii
b
a
xandc
NodesxWeightsc
xfcdxxf
CISE301_Topic7 KFUPM 45
Lagrange InterpolationLagrange Interpolation
b
a ii
n
iii
b
a
b
a i
n
ii
b
a n
b
a
n
n
b
a n
b
a
dxxcwherexfcdxxf
dxxfxdxxPdxxf
xxx
xPwhere
dxxPdxxf
)()()(
)()()()(
,...,, :nodes at the
f(x) esinterpolat that polynomial a is )(
)()(
0
0
10
CISE301_Topic7 KFUPM 46
QuestionQuestion
What is the best way to choose the nodes and the weights?
CISE301_Topic7 KFUPM 47
Theorem Theorem
1.2norder of spolynomial allfor exact be willformula The
)()()(
: then)( of zeros theare,...,,,Let
00)(
:such that 1n degree of polynomial nontrivial a be Let
0
210
dxxcwherexfcdxxf
xqxxxx
nkdxxqx
q
i
b
ai
n
iii
b
a
n
kb
a
CISE301_Topic7 KFUPM 48
Weighted Gaussian Weighted Gaussian QuadratureQuadratureTheoremTheorem
12norder of
polynomial a isnever exact whe be willformula The
)(,)()(
:)()()(
: then)( of zeros theare,...,,,Let
00)()(
:such that 1 degree of polynomial nontrivial a be Let
0
0
210
f(x)
xx
xxxdxxwxc
wherexfcdxxwxf
xqxxxx
nkdxxwxqx
nq
n
ijj ji
jii
b
ai
n
iii
b
a
n
kb
a
CISE301_Topic7 KFUPM 49
Determining The Weights and Determining The Weights and NodesNodes
?5order of
spolynomial allfor exact is formula that theso
weights theand nodes select the wedo How
)()()()( 221100
1
1
xfcxfcxfcdxxf
CISE301_Topic7 KFUPM 50
Determining The Weights and Determining The Weights and NodesNodesSolutionSolution
5,3,0solution possible One
0)(
0)(
0)(
:satisfymust )(
)(
3120
1
1
2
1
1
1
1
33
2210
aaaa
dxxxq
xdxxq
dxxq
xq
xaxaxaaxqLet
CISE301_Topic7 KFUPM 51
Determining The Weights and Determining The Weights and NodesNodesSolutionSolution
5
30
5
3)(
use we weightsobtain the To
5
3 0,,
5
3are nodes The
5
3 0, are)(
53)(
210
1
1
210
3
fAfAfAdxxf
xxx
xqofroots
xxxqLet
CISE301_Topic7 KFUPM 52
Determining The Weights and Determining The Weights and NodesNodesSolutionSolution
5
3
9
50
9
8
5
3
9
5)(
2)(n Quadrature Gauss The
9
5 ,
9
8,
9
5are weightsThe
5
3 0,,
5
3are nodes The
1
1
210
210
fffdxxf
AAA
xxx
CISE301_Topic7 KFUPM 53
Gaussian QuadratureGaussian QuadratureSee more in Table 22.1 (page 626)See more in Table 22.1 (page 626)
236926.0,478628.0,568889.0,478628.0,236926.0
906179.0,538469.0,00000.0,538469.0,906179.04
34785.0,65214.0,65214.0,34785.0
86113.0,33998.0,33998.0,86113.03
555556.0,888889.0,555556.0
774596.0,000000.0,774596.02
1,1
57735.0,57735.01
)()(
43210
43210
3210
3210
210
210
10
10
0
1
1
ccccc
xxxxxn
cccc
xxxxn
ccc
xxxn
cc
xxn
xfcdxxfn
iii
CISE301_Topic7 KFUPM 54
Error Analysis for Gauss Error Analysis for Gauss QuadratureQuadrature
12norder of spolynomial allfor exact be willformula The
]1,1[),()!22()32(
)!1(2Error
:satisfieserror true theThen,
formula, Quadrature Gauss the
toaccording selected are
)()(
:by edapproximat be)( integral theLet
)22(3
432n
0
n
ii
n
iii
b
a
b
a
fnn
n
xandcwhere
xfcdxxf
dxxf
CISE301_Topic7 KFUPM 55
ExampleExample
1.n with QuadratureGaussian using1
0
2
dxeEvaluate x
b? and a arbitrary for
)(:compute toformula theuse wedo How
3
1
3
1)(
1
1
b
adxxf
ffdxxf
1
1 222)( dt
abt
abf
abdxxf
b
a
CISE301_Topic7 KFUPM 56
ExampleExample
22
22
5.3
15.05.
3
15.0
1
15.5.1
0
2
1
2
1
ee
dtedxe tx
CISE301_Topic7 KFUPM 57
Improper IntegralsImproper Integrals
1
0 221 2
1
1 2a
1
111 :
function. new on the method apply the and
)0 assuming(,11
)(
following thelikeation transforma Use
)or is limits theof (one integralsimproper eapproximat
todirectly used benot can earlier discussed Methods
dt
t
tdx
xExample
abdtt
ft
dxxf a
b
b