Download - Math 151A - Spring 2020 - Week 10
Math 151A - Spring 2020 - Week 10
Today: Numerical Integration
• Composite Rules
• Degree of Precision
• Gaussian Quadrature
Math 151A - Spring 2020 - Week 10
Composite Trapezoidal Rule
Z b
af (x)dx = h
0
@1
2f (a) +
n�1X
j=1
f (xj) +1
2f (b)
1
A� b � a
12h2f 00(⇠)
h =b � an
mesh x0, ..., xn
Tmr
Math 151A - Spring 2020 - Week 10
Composite Simpson’s Rule
Z b
a
f (x)dx =h3
0
@f (a) + 2(n/2)�1X
j=1
f (x2j) + 4n/2X
j=1
f (x2j�1) + f (b)
1
A�b � a180
h4f (4)(⇠)
h =b � an
mesh x0, ..., xn n even
Error
Math 151A - Spring 2020 - Week 10
Composite Midpoint Rule
Z b
af (x)dx = 2h
n/2X
j=0
f (x2j) +b � a
6h2f 00(⇠)
h =b � an + 2
mesh x�1, x0, ..., xn+1 n even
Gmr
T grimsinink
ormyeloidmesh
Math 151A - Spring 2020 - Week 10
Example 1. Determine the value of n required to approximateR 20 e2x sin 3xdx with an accuracy of 1⇥ 10
�4using the Composite
Midpoint Rule.
t.mn b ah2f S c 1 10 4 III h bnz n z
6fix e sm3x
f x 2e sin3 3e cos3X
f X 4e sin3 6e ca3 62 3 9e2 sih3X
Se2sin3x the 2 as3
1BI h f G e 151421 max tf x I6 b XEfo23
26 212ffgox.gg 5e2Xsin3Xtl2e2Xas3xI
Math 151A - Spring 2020 - Week 10
Example 1. Determine the value of n required to approximateR 20 e2x sin 3xdx with an accuracy of 1⇥ 10
�4using the Composite
Midpoint Rule.
Iknew f 5 I 5 f 212 xmefox.gg l5e2xsin3X i112e2xas3x1
EKITI.ES l 5e2xltll2e2xl
E f 212 5e4 the n 12 n
f 212 Hell
En l7eseenext slide
piety 12
n 4
Math 151A - Spring 2020 - Week 10
Example 1. Determine the value of n required to approximateR 20 e2x sin 3xdx with an accuracy of 1⇥ 10
�4using the Composite
Midpoint Rule.
f 1 Che c if8117M I6th1212 104
Yate 104 c In1212
n12 4 I 3517.894 7 n1223518
nTr3
Math 151A - Spring 2020 - Week 10
Example 2. Write a program to approximate the integral
Z 2
0x2e�x2
dx
using the Composite Trapezoidal rule with n = 8, Composite Simpson’s
rule with n = 8, and the Composite Midpoint rule with n = 6.
See codes
Math 151A - Spring 2020 - Week 10
The degree of precision of a quadrature formula is the largest positive
integer n such that formula is exact for xk for each k = 0, 1, ..., n.
Trapezoidal rule has degree of precision 1.
Simpson’s rule has degree of precision 3.
Math 151A - Spring 2020 - Week 10
Example 3. A program was written that implements the composite
trapezoidal method to approximate integrals of the formR 10 f (x)dx . This
program was tested on monomials of increasing degrees using double
precision arithmetic and the number of panels N = 1000. The results are
as follows. Is this program working correctly? Explain your answer.
f (x) Computed Approximation
1 1.000500000000
x 0.500500000000
x2 0.333833500000
x3 0.250500250000
x4 0.200500333333
TrapezoidalruleDop I not Iexactfor Axl I not'zand fix _X
ft dx Xl I 0 1 program is not Wahabcorrectly because not
fixDX Ix lot I 0 12 exact fr fix L fix X
Math 151A - Spring 2020 - Week 10
Gaussian Quadrature
Z 1
�1f (x)dx ⇡
nX
i=1
ciP(xi )
Degree of precision is 2n � 1.
xi values come from the roots of Legendre polynomials. Some Legendre
polynomials:
P0(x) = 1, P1(x) = x , P2(x) = x2 � 1
3
P3(x) = x3 � 3
5x , P4(x) = x4 � 6
7x2 +
3
35
Sune Anduin
1 If
Math 151A - Spring 2020 - Week 10
Example 4.
(a) Derive the 3-point (Legendre) Gaussian Quadrature to approximateR 1�1 f (x)dx .
(b) What is the degree of precision in (a)?
(c) Show that the 3-point Gaussian quadrature can be used for
approximatingR ba f (x)dx by doing a simple change of variables and
applying this to approximate
Z 4
0
cos x
x + 1dx
b 3 point n 32n 1 213 1 50
a fi fix DX C FIX tGfCXz tczfCX3
Math 151A - Spring 2020 - Week 10
Example 4. continued
(a) Derive the 3-point (Legendre) Gaussian Quadrature to approximateR 1�1 f (x)dx .
P X3 ZX O fifandx Iff ff t f o tGffffX x23g 0 few 1 fCx7 x fCX7 X2X o tf
Xi Pg 112 0 X3 ff IfidXXl 2
G Itcz g 15CITE 15 2
HX X fixdx zxyj oz ffcr FEG
09ffflG.co fftG 0
4 5
Math 151A - Spring 2020 - Week 10
Example 4. continued
(a) Derive the 3-point (Legendre) Gaussian Quadrature to approximateR 1�1 f (x)dx .
fun _x2 fix'dx XIIIafrtttecoy.ia.fr i2Ia
Icz3atczgIqtCztCz2 cz Kg 2
I 3 city24 11 If flxldX2 fffE 185ft 1 Igf Ff
94 59103 59
Math 151A - Spring 2020 - Week 10
Example 4. continued
(c) Show that the 3-point Gaussian quadrature can be used for
approximatingR ba f (x)dx by doing a simple change of variables and
applying this to approximate
Z 4
0
cos x
x + 1dx
fi fix DXa Ffl Ff Igflo t Ff ff
fabflydy L f z DX l l l Ca b
i i iy bzaxtb.at
2
y b a X a
dy KID
Math 151A - Spring 2020 - Week 10
Example 4. continued
(c) Show that the 3-point Gaussian quadrature can be used for
approximatingR ba f (x)dx by doing a simple change of variables and
applying this to approximate
Z 4
0
cos x
x + 1dx
figfxdxegfl.FI t8qflol Igf ff
fabfly1dy f f 4 4 112 bazdx
BEf if Hatta DXbzafigfflbFH.tn t f f HI
Eff fEt
Math 151A - Spring 2020 - Week 10
Example 4. continued
(c) Show that the 3-point Gaussian quadrature can be used for
approximatingR ba f (x)dx by doing a simple change of variables and
applying this to approximate
Z 4
0
cos x
x + 1dx
bfmdfzafqffcbalt.FI btoy 8qffbtay a o b 4u I fly cost
Igf lba1FsIb x11
fo af dxa2 Eff.tk t8qffz tIgff4ffz4
0.2798850
Math 151A - Spring 2020 - Week 10
Example 5. Show that the formula Q(P) =Pn
i=1 ciP(xi ) cannot have
degree of precision greater than 2n � 1, regardless of the choice of
c1, ..., cn and x1, ..., xn. (Hint: construct a polynomial that has double
root at each of the xi values.)
Suppose by antradichui that QLP has degreeofprecision2h
Consider PIX x Xi X Xa X Xn whichhasdegree2h
f if DX a ftCiflXoSince DOP 2h then f pcxtdx f.ciPHIonRHS CiPui
on LHS f pcxjdx f.it xixXiTdx OZO
Antrudillin 070 Therefore DOP is at mist 2n 1