Professional Documents
Culture Documents
Lecture.24 27
Lecture.24 27
Lecture 24
Shripad M. Garge.
IIT Bombay
( shripad@math.iitb.ac.in )
2021-2022
1/54
shripad@math.iitb.ac.in MA214 (2021-2022) L24
Composite numerical integration
2/54
shripad@math.iitb.ac.in MA214 (2021-2022) L24
An example
ż4
We have e x dx “ e 4 ´ e 0 “ 53.5981500331.
0
1
Using Simpson’s -rule on r0, 4s:
3
ż4
2
e x dx « pe 0 ` 4e 2 ` e 4 q “ 56.7695829526.
0 3
The error is then ´3.17143291943 which is rather unacceptable.
1
Using Simpson’s -rule to r0, 2s and r2, 4s:
3
ż4 ż2 ż4
x x
e dx “ e dx ` e x dx
0 0 2
1 0 1
“ pe ` 4e ` e 2 q ` pe 2 ` 4e 3 ` e 4 q
3 3
“ 53.8638457459
3/54
shripad@math.iitb.ac.in MA214 (2021-2022) L24
The example, continued
1
Now, we apply Simpson’s -rule to the subintervals of length 1:
3
ż4 ż1 ż2 ż3 ż4
e x dx “ x
e dx ` x
e dx ` x
e dx ` e x dx
0 0 1 2 3
1 0 1
“ pe ` 4e 1{2 ` eq ` pe ` 4e 3{2 ` e 2 q
6 6
1 2 1
` pe ` 4e 5{2 ` e 3 q ` pe 3 ` 4e 7{2 ` e 4 q
6 6
“ 53.616220796
1
The errors naturally decrease when we apply the Simpson’s -rule
3
to smaller and smaller subintervals.
5/54
shripad@math.iitb.ac.in MA214 (2021-2022) L24
General case
6/54
shripad@math.iitb.ac.in MA214 (2021-2022) L24
General case
8/54
shripad@math.iitb.ac.in MA214 (2021-2022) L24
Composite Trapezoidal rule
9/54
shripad@math.iitb.ac.in MA214 (2021-2022) L24
Composite midpoint rule
There exists a µ P pa, bq for which the Composite Midpoint rule for
n ` 2 subintervals can be written with its error term as
żb n{2
ÿ b´a 2 2
f pxqdx “ 2h f px2j ` h f pµq.
a j“0
6
10/54
shripad@math.iitb.ac.in MA214 (2021-2022) L24
Composite midpoint rule
11/54
shripad@math.iitb.ac.in MA214 (2021-2022) L24
An example
żπ
Let us compute the integral sin xdx using the above two
0
methods such that the error is less than 0.00002.
πh2 πh2
| sin µ| ď ă 0.00002 so h ă 0.00874038744.
12 12
Since h “ π{n, this gives
n ě 360.
12/54
shripad@math.iitb.ac.in MA214 (2021-2022) L24
The example, continued
We now apply the composite Simpson’s rule. The error in this rule
is given by ˇ 4
ˇ πh p4q ˇ πh4
ˇ
ˇ 180 f pµqˇ “ 180 | sin µ|
ˇ ˇ
πh4 πh4
| sin µ| ď ă 0.00002 so h ă 0.18398743167.
180 180
Since h “ π{n, this gives
n ě 18.
The composite Simpson’s rule gives the required accuracy for a
smaller number of subintervals.
13/54
shripad@math.iitb.ac.in MA214 (2021-2022) L24
Comparison of the composite rules
14/54
shripad@math.iitb.ac.in MA214 (2021-2022) L24
MA 214: Introduction to numerical analysis
Lecture 25
Shripad M. Garge.
IIT Bombay
( shripad@math.iitb.ac.in )
2021-2022
15/54
shripad@math.iitb.ac.in MA214 (2021-2022) L25
Round-off error
That is, the round-off error does not depend on the number of
calculations performed.
16/54
shripad@math.iitb.ac.in MA214 (2021-2022) L25
Stability of composite integration rules
19/54
shripad@math.iitb.ac.in MA214 (2021-2022) L25
A problem with composite methods
20/54
shripad@math.iitb.ac.in MA214 (2021-2022) L25
A problem with composite methods
ż4
Let us assume that we need to compute y pxqdx.
0
21/54
shripad@math.iitb.ac.in MA214 (2021-2022) L25
Adaptive quadrature method
Question
How can we determine what technique should be applied on
various portions of the interval of integration, and how accurate
can we expect the final approximation to be?
22/54
shripad@math.iitb.ac.in MA214 (2021-2022) L25
Adaptive quadrature method
where
h
Spa, bq “ rf paq ` 4f pa ` hq ` f pbqs .
3
23/54
shripad@math.iitb.ac.in MA214 (2021-2022) L25
Adaptive quadrature method
24/54
shripad@math.iitb.ac.in MA214 (2021-2022) L25
Adaptive quadrature method
h5 p4q 1 h5
ˆ ˙ ˆ ˙ ˆ ˙
a`b a`b
Spa, bq´ f pξq « S a, `S ,b ´ f p4q pξq
90 2 2 16 90
or
h5 p4q
„ ˆ ˙ ˆ ˙
16 a`b a`b
f pξq « Spa, bq ´ S a, ´S ,b .
90 15 2 2
we expect
ˇż b ˆ ˙ ˆ ˙ˇ
ˇ f pxqdx ´ S a, a ` b ´ S a ` b , b ˇ ă
ˇ ˇ
ˇ
a 2 2 ˇ
` ˘ ` ˘
and S a, a`b
2 ` S a`b
2 , b ż is assumed to be a sufficiently
b
accurate approximation to f pxqdx.
a
26/54
shripad@math.iitb.ac.in MA214 (2021-2022) L25
Adaptive quadrature method
ˇ ` ˘ ` ˘ˇ
When ˇSpa, bq ´ S a, a`b2 ´ S a`b
2 , b ă 15, we apply the
ˇ
Simpson’s rule individually to each subinterval, ra, pa ` bq{2s and
rpa ` bq{2, bs.
29/54
shripad@math.iitb.ac.in MA214 (2021-2022) L25
MA 214: Introduction to numerical analysis
Lecture 26
Shripad M. Garge.
IIT Bombay
( shripad@math.iitb.ac.in )
2021-2022
30/54
shripad@math.iitb.ac.in MA214 (2021-2022) L26
Gaußian quadrature
31/54
shripad@math.iitb.ac.in MA214 (2021-2022) L26
Gaußian quadrature
32/54
shripad@math.iitb.ac.in MA214 (2021-2022) L26
Gaußian quadrature
33/54
shripad@math.iitb.ac.in MA214 (2021-2022) L26
Gaußian quadrature
34/54
shripad@math.iitb.ac.in MA214 (2021-2022) L26
Gaußian quadrature
36/54
shripad@math.iitb.ac.in MA214 (2021-2022) L26
Gaußian quadrature, n “ 2
f pxq “ a0 ` a1 x ` a2 x 2 ` a3 x 3
for some a0 , a1 , a2 , a3 .
37/54
shripad@math.iitb.ac.in MA214 (2021-2022) L26
Gaußian quadrature, n “ 2
Similarly, we have
ża ż1
2
c1 x1 ` c2 x2 “ xdx “ 0, c1 x12 ` c2 x22 “ x 2 dx “
´1 ´1 3
ż1
and c1 x13 ` c2 x23 “ x 3 dx “ 0. We can solve these equations to
´1 ? ?
´ 3 3
obtain c1 “ 1 “ c2 , x1 “ and x2 “ .
3 3
The approximation formula then reads
ż1 ˆ ? ˙ ˆ? ˙
´ 3 3
f pxqdx « f `f
´1 3 3
38/54
shripad@math.iitb.ac.in MA214 (2021-2022) L26
Legendre polynomials
39/54
shripad@math.iitb.ac.in MA214 (2021-2022) L26
Legendre polynomials
Theorem
Let x1 , x2 , . . . , xn be the roots of Pn pxq and define for each
i “ 1, 2, . . . , n,
ż1 ź n
x ´ xj
ci “ dx.
´1 xi ´ xj
j “1
j ‰i
If Ppxq is a polynomial of degree ă 2n then
ż1 n
ÿ
Ppxqdx “ ci Ppxi q.
´1 i“1
40/54
shripad@math.iitb.ac.in MA214 (2021-2022) L26
Legendre polynomials
But they have also been tabulated extensively. We can just use
them off the shelf.
For instance, for P3 the nodes and the coefficients are as follows:
xi ci
0.7745966692 0.5555555556
0.0000000000 0.8888888889
-0.7745966692 0.5555555556
ż1
Let us use these values to compute e x cos xdx.
´1
41/54
shripad@math.iitb.ac.in MA214 (2021-2022) L26
An example
We have
ż1
e x cos xdx « 0.5555555556 e 0.7745966692 cosp0.7745966692q
´1
` 0.8888888889
` 0.5555555556 e ´0.7745966692 cosp´0.7745966692q
“ 1.9333904.
42/54
shripad@math.iitb.ac.in MA214 (2021-2022) L26
MA 214: Introduction to numerical analysis
Lecture 27
Shripad M. Garge.
IIT Bombay
( shripad@math.iitb.ac.in )
2021-2022
43/54
shripad@math.iitb.ac.in MA214 (2021-2022) L27
What next in numerical integration?
44/54
shripad@math.iitb.ac.in MA214 (2021-2022) L27
Multiple integrals
We start with x
f px, y qdA
R
where
R “ tpx, y q : a ď x ď b, c ď y ď du,
is a rectangular region in the plane.
We have
x ż b ˆż d ˙
f px, y qdA “ f px, y qdy dx.
R a c
45/54
shripad@math.iitb.ac.in MA214 (2021-2022) L27
Multiple trapezoidal rule
We further get
żbżd żbˆ ˙„ ˆ ˙
d ´c c `d
f px, y qdydx « f px, cq ` f px, dq ` 2f x,
a c a 4 2
„ ˆ ˙
pb ´ aqpd ´ cq a`b c `d
“ f pa, cq ` f pa, dq ` f pb, cq ` f pb, dq ` 4f ,
16 2 2
" ˆ ˙ ˆ ˙ ˆ ˙ ˆ ˙*
a`b a`b c `d c `d
`2 f ,c ` f , d ` f a, ` f b, .
2 2 2 2
46/54
shripad@math.iitb.ac.in MA214 (2021-2022) L27
Multiple trapezoidal rule
47/54
shripad@math.iitb.ac.in MA214 (2021-2022) L27
Multiple Simpson’s rule
żd
we first approximate f px, y qdy , treating x as constant, using
c
the composite Simpson’s rule.
48/54
shripad@math.iitb.ac.in MA214 (2021-2022) L27
Multiple Simpson’s rule
Let yj “ c ` jk, for each j “ 0, 1, . . . , m. Then
»
żd pm{2q´1 m{2
k– ÿ ÿ
f px, y qdy “ f px, y0 q ` 2 f px, y2j q ` 4 f px, y2j´1 q
c 3 j“1 j“1
pd ´ cqk 4 B 4 f
`f px, ym q ´ px, µq
180 By 4
49/54
shripad@math.iitb.ac.in MA214 (2021-2022) L27
Multiple Simpson’s rule
The final answer then is
x
#« pn{2q´1 n{2
ff
hk ÿ ÿ
f px, y qdA « f px0 , y0 q ` 2 f px2i , y0 q ` 4 f px2i´1 , y0 q ` f pxn , y0 q
9 i“1 i“1
R
«pm{2q´1 pm{2q´1 n{2
ÿ ÿ pn{2q´1
ÿ pm{2q´1
ÿ ÿ
`2 f px0 , y2j q ` 2 f px2i , y2j q ` 4 f px2i´1 , y2j q
j“1 j“1 i“1 j“1 i“1
pm{2q´1
ff «m{2 m{2
ÿ ÿ ÿ pn{2q´1
ÿ
` f pxn , y2j q ` 4 f px0 , y2j´1 q ` 2 f px2i , y2j´1 q
j“1 j“1 j“1 i“1
Let us do an example.
50/54
shripad@math.iitb.ac.in MA214 (2021-2022) L27
An example
The step sizes for this application are h “ p2.0 ´ 1.4q{4 “ 0.15 and
k “ p1.5 ´ 1.0q{2 “ 0.25.
51/54
shripad@math.iitb.ac.in MA214 (2021-2022) L27
The example, continued
52/54
shripad@math.iitb.ac.in MA214 (2021-2022) L27
The example, continued
53/54
shripad@math.iitb.ac.in MA214 (2021-2022) L27
Error formula
x
The error in the formula for f px, y qdA is
R
pd ´ cqpb ´ aq 4 B 4 f 4
„
4 B f
E “´ h pη̄, µ̄q ` k pη̂, µ̂q
180 Bx 4 By 4
ď 4.72 ˆ 10´6
54/54
shripad@math.iitb.ac.in MA214 (2021-2022) L27