MA128 ALecture Week 8
MA128 ALecture Week 8
MA128 ALecture Week 8
I Gaussian quadrature
Z 1
f (x) dx ≈ c1 f (x1 ) + c2 f (x2 ) + · · · + cn f (xn ),
−1
I Gaussian quadrature
Z 1
f (x) dx ≈ c1 f (x1 ) + c2 f (x2 ) + · · · + cn f (xn ),
−1
I Gaussian quadrature
Z 1
f (x) dx ≈ c1 f (x1 ) + c2 f (x2 ) + · · · + cn f (xn ),
−1
Z 1 Z 1 Z 1
f (x) dx = H(x) dx + R(x) dx
−1 −1 −1
Hermite Interpolation, with Gaussian Quadrature
Z 1 Z 1 Z 1
f (x) dx = H(x) dx + R(x) dx
−1 −1 −1
Z 1
deg(H)≤2n−1
======== c1 P(x1 ) + c2 P(x2 ) + · · · + cn P(xn ) + R(x) dx
−1
Hermite Interpolation, with Gaussian Quadrature
Z 1 Z 1 Z 1
f (x) dx = H(x) dx + R(x) dx
−1 −1 −1
Z 1
deg(H)≤2n−1
======== c1 P(x1 ) + c2 P(x2 ) + · · · + cn P(xn ) + R(x) dx
−1
magic
===== c1 f (x1 ) + c2 f (x2 ) + · · · + cn f (xn )
Z 1 (2n)
f (ξ(x))
+ (x − x1 )2 (x − x2 )2 · · · (x − xn )2 dx
−1 (2n)!
Hermite Interpolation, with Gaussian Quadrature
Z 1 Z 1 Z 1
f (x) dx = H(x) dx + R(x) dx
−1 −1 −1
Z 1
deg(H)≤2n−1
======== c1 P(x1 ) + c2 P(x2 ) + · · · + cn P(xn ) + R(x) dx
−1
magic
===== c1 f (x1 ) + c2 f (x2 ) + · · · + cn f (xn )
Z 1 (2n)
f (ξ(x))
+ (x − x1 )2 (x − x2 )2 · · · (x − xn )2 dx
−1 (2n)!
= c1 f (x1 ) + c2 f (x2 ) + · · · + cn f (xn )
f (2n) (ξ) 1
Z
+ (x − x1 )2 (x − x2 )2 · · · (x − xn )2 dx
(2n)! −1
Hermite Interpolation, with Gaussian Quadrature
Z 1 Z 1 Z 1
f (x) dx = H(x) dx + R(x) dx
−1 −1 −1
Z 1
deg(H)≤2n−1
======== c1 P(x1 ) + c2 P(x2 ) + · · · + cn P(xn ) + R(x) dx
−1
magic
===== c1 f (x1 ) + c2 f (x2 ) + · · · + cn f (xn )
Z 1 (2n)
f (ξ(x))
+ (x − x1 )2 (x − x2 )2 · · · (x − xn )2 dx
−1 (2n)!
= c1 f (x1 ) + c2 f (x2 ) + · · · + cn f (xn )
f (2n) (ξ) 1
Z
+ (x − x1 )2 (x − x2 )2 · · · (x − xn )2 dx
(2n)! −1
def
== c1 f (x1 ) + c2 f (x2 ) + · · · + cn f (xn ) + R
Gaussian Quadrature Error Estimate
1
f (2n) (ξ)
Z
R = (x − x1 )2 (x − x2 )2 · · · (x − xn )2 dx
(2n)! −1
Gaussian Quadrature Error Estimate
1
f (2n) (ξ)
Z
R = (x − x1 )2 (x − x2 )2 · · · (x − xn )2 dx
(2n)! −1
!
22n 3
(n!) (n − 1)! 4−n f (2n) (ξ)
= f (2n) (ξ) = O .
(2n + 1)! (2n)! (2n − 1)! (2n)!
Gaussian Quadrature Error Estimate
1
f (2n) (ξ)
Z
R = (x − x1 )2 (x − x2 )2 · · · (x − xn )2 dx
(2n)! −1
!
22n 3
(n!) (n − 1)! 4−n f (2n) (ξ)
= f (2n) (ξ) = O .
(2n + 1)! (2n)! (2n − 1)! (2n)!
!
1 4−n f (2n) (ξ)
Z
f (x) dx = c1 f (x1 ) + c2 f (x2 ) + · · · + cn f (xn ) + O .
−1 (2n)!
Gaussian Quadrature:
I points different for different n.
R = {(x, y ) | a ≤ x ≤ b, c ≤ y ≤ d. }
Double Integral = Integral of Integral
Z Z Z b Z d
f (x, y ) dA = f (x, y ) dy dx
R a c
Z b
= g (x) dx,
a
Z d
def
where g (x) == f (x, y ) dy .
c
Approach
Rb
I Approximate a g (x) dx with quadrature.
I For any given xi , approximate g (xi ) with quadrature.
RR Rb Rd
R f (x, y ) dA = Rb a g (x) dx, g (x) = cf (x, y ) dy
I Approximate a g (x) dx with n-point quadrature:
Z b
g (x) dx = c1 g (x1 ) + c2 g (x2 ) + · · · + cn g (xn ) + R(g )
a
RR Rb Rd
R f (x, y ) dA = Rb a g (x) dx, g (x) = cf (x, y ) dy
I Approximate a g (x) dx with n-point quadrature:
Z b
g (x) dx = c1 g (x1 ) + c2 g (x2 ) + · · · + cn g (xn ) + R(g )
a
n
Z Z !
X
f (x, y ) dA = ci g (xi ) + R(g )
R i=1
Xn Xm
= c i b (xi , ·)) + R(g )
cbj f (xi , yj ) + R(f
i=1 j=1
RR Rb Rd
R f (x, y ) dA = Rb a g (x) dx, g (x) = cf (x, y ) dy
I Approximate a g (x) dx with n-point quadrature:
Z b
g (x) dx = c1 g (x1 ) + c2 g (x2 ) + · · · + cn g (xn ) + R(g )
a
n
Z Z !
X
f (x, y ) dA = ci g (xi ) + R(g )
R i=1
Xn Xm
= c i b (xi , ·)) + R(g )
cbj f (xi , yj ) + R(f
i=1 j=1
n X
m n
!
X X
= ci cbj f (xi , yj ) + b (xi , ·))
ci R(f + R(g ).
i=1 j=1 i=1
RR Rb Rd
R f (x, y ) dA = a g (x) dx, g (x) = cf (x, y ) dy
R = {(x, y ) | a ≤ x ≤ b, c ≤ y ≤ d. }
Z b
g (x) dx = c1 g (x1 ) + c2 g (x2 ) + · · · + cn g (xn ) + R(g )
a
Z d
f (xi , y ) dy = cb1 f (x1 , y1 ) + cb2 f (xi , y2 ) + · · · + cbm f (xi , ym )
c
b (xi , ·))
+ R(f
RR Rb Rd
R f (x, y ) dA = a g (x) dx, g (x) = cf (x, y ) dy
R = {(x, y ) | a ≤ x ≤ b, c ≤ y ≤ d. }
Z b
g (x) dx = c1 g (x1 ) + c2 g (x2 ) + · · · + cn g (xn ) + R(g )
a
Z d
f (xi , y ) dy = cb1 f (x1 , y1 ) + cb2 f (xi , y2 ) + · · · + cbm f (xi , ym )
c
b (xi , ·))
+ R(f
n X
m n
Z Z !
X X
f (x, y ) dA = ci cbj f (xi , yj ) + b (xi , ·))
ci R(f + R(g )
R i=1 j=1 i=1
n X
X m
≈ ci cbj f (xi , yj ).
i=1 j=1
R = {(x, y ) | a ≤ x ≤ b, c ≤ y ≤ d. }
Example, Simpson’s Rule with m = n = 3:
(x1 , x2 , x3 ) = a, a+b
I Simpson’s Rule on [a, b]: 2 , b .
c+d
I Simpson’s Rule on [c, d]: (y1 , y2 , y3 ) = c, 2 , d .
RR Pn Pm Pn b (xi , ·)) + R(g )
R
f (x, y ) dA = i=1 j=1 ci c
bj f (xi , yj ) + i=1 ci R(f
R = {(x, y ) | a ≤ x ≤ b, c ≤ y ≤ d. }
Example, Simpson’s Rule with m = n = 3:
(x1 , x2 , x3 ) = a, a+b
I Simpson’s Rule on [a, b]: 2 , b .
c+d
I Simpson’s Rule on [c, d]: (y1 , y2 , y3 ) = c, 2 , d .
RR Pn Pm Pn b (xi , ·)) + R(g )
R
f (x, y ) dA = i=1 j=1 ci c
bj f (xi , yj ) + i=1 ci R(f
R = {(x, y ) | a ≤ x ≤ b, c ≤ y ≤ d. }
Example, m = n = 3:
(x1 , x2 , x3 ) = a, a+b
I Simpson’s Rule on [a, b]: 2 ,b .
b
h5 (4)
Z
g (x) dx = c1 g (x1 ) + c2 g (x2 ) + c3 g (x3 ) − g (ξ),
a 90
b−a h
h= , (c1 , c2 , c3 ) = (1, 4, 1) .
2 3
(y1 , y2 , y3 ) = c, c+d
I Simpson’s Rule on [c, d]: 2 ,d .
d
k 5 ∂4f
Z
f (xi , y ) dy = cb1 f (xi , y1 )+b
c2 f (xi , y2 )+b
c3 f (xi , y3 )− (xi , ηi ),
c 90 ∂ 4 y
d −c k
k= , (b
c1 , cb2 , cb3 ) = (1, 4, 1) .
2 3
n X
m m
!
k5 ∂4f
Z Z X X
f (x, y ) dA = ci cbj f (xi , yj ) − ci 4 (xi , ηi )
R 90 ∂ y
i=1 j=1 i=1
h5 b ∂ 4 f
Z
− (ξ, y )dy
90 a ∂ 4 x
n X
m m
!
Z Z X k 5 X ∂ 4f
f (x, y ) dA = ci cbj f (xi , yj ) − ci 4 (xi , ηi )
R 90 ∂ y
i=1 j=1 i=1
h5 b ∂ 4 f
Z
− (ξ, y )dy
90 a ∂ 4 x
n X m m
!
X k 5 X ∂4f b
= ci cbj f (xi , yj ) − ci (ξ, ηb)
90 ∂4y
i=1 j=1 i=1
h5 ∂4f
− (b − a) 4 (ξ, η)
90 ∂ x
n X
m m
!
Z Z X k 5 X ∂ 4f
f (x, y ) dA = ci cbj f (xi , yj ) − ci 4 (xi , ηi )
R 90 ∂ y
i=1 j=1 i=1
h5 b ∂ 4 f
Z
− (ξ, y )dy
90 a ∂ 4 x
n X m m
!
X k 5 X ∂4f b
= ci cbj f (xi , yj ) − ci (ξ, ηb)
90 ∂4y
i=1 j=1 i=1
h5 ∂4f
− (b − a) 4 (ξ, η)
90 ∂ x
n X
X m
= ci cbj f (xi , yj )
i=1 j=1
4 4
(b − a)(d − c) 4∂ f b 4∂ f
− k 4 (ξ, ηb) + h 4 (ξ, η) .
180 ∂ y ∂ x
RR Pn Pm Pn b (xi , ·)) + R(g )
R
f (x, y ) dA = i=1 j=1 ci c
bj f (xi , yj ) + i=1 ci R(f
R = {(x, y ) | a ≤ x ≤ b, c ≤ y ≤ d. }
Example: Composite Simpson Rules.
RR Pn Pm Pn b (xi , ·)) + R(g )
R
f (x, y ) dA = i=1 j=1 ci c
bj f (xi , yj ) + i=1 ci R(f
R = {(x, y ) | a ≤ x ≤ b, c ≤ y ≤ d. }
Example: Composite Simpson Rules.
I Composite Simpson on [a, b], xi =a+(i−1)h, 1≤i ≤n, h= b−a .
n−1
R = {(x, y ) | a ≤ x ≤ b, c ≤ y ≤ d. }
Example: Composite Simpson Rules.
I Composite Simpson on [a, b], xi =a+(i−1)h, 1≤i ≤n, h= b−a .
n−1
d−c
I Composite Simpson on [c, d], yj =c+(j−1)k, 1≤ j ≤m, k = m−1 .
4 4
b (xi , ·)) = − (d − c)k ∂ f (xi , ηi )
R(f
180 ∂4y
n n
!
X (d − c)k 4 X ∂4f b
b (xi , ·)) = −
ci R(f ci (ξ, ηb)
180 ∂4y
i=1 i=1
(b − a)(d − c)k 4 ∂ 4 f b
= − (ξ, ηb).
180 ∂4y
Error Estimate, Double Integral with Composite Simpson
R = {(x, y ) | a ≤ x ≤ b, c ≤ y ≤ d. }
Z Z n X
X m
f (x, y ) dA = ci cbj f (xi , yj )
R i=1 j=1
4f 4
(b − a)(d − c) 4∂ 4∂ f
− k 4 (ξ, ηb) + h 4 (ξ, η) ,
b
180 ∂ y ∂ x
b−a d −c
h= , k= .
n−1 m−1
RR
Example: R log(x + 2y ) dA with n = 7, m = 5
(b − a)(d − c) 4 ∂ 4 f b ∂4f
Quad Error = k 4 (ξ, ηb) + h4 4 (ξ, η)
180 ∂ y ∂ x
(2.4 − 1.2)(1 − 0.2)
0.24 × 14.648 + 0.24 × 0.91553
≤
180
RR
Example: R log(x + 2y ) dA with n = 7, m = 5
(b − a)(d − c) 4 ∂ 4 f b ∂4f
Quad Error = k 4 (ξ, ηb) + h4 4 (ξ, η)
180 ∂ y ∂ x
(2.4 − 1.2)(1 − 0.2)
0.24 × 14.648 + 0.24 × 0.91553
≤
180
≈ 1.328 × 10−4 .
RR
Example: R log(x + 2y ) dA with n = 7, m = 5
Z Z
log(x + 2y ) dA = 1.0360481 · · ·
R
RR
Example: R log(x + 2y ) dA with n = 7, m = 5
Z Z
log(x + 2y ) dA = 1.0360481 · · ·
R
Z Z 7 X
X 5
log(x + 2y ) dA ≈ ci cbj f (xi , yj )
R i=1 j=1
= 1.0360327 · · · .
RR
Example: R log(x + 2y ) dA with n = 7, m = 5
Z Z
log(x + 2y ) dA = 1.0360481 · · ·
R
Z Z 7 X
X 5
log(x + 2y ) dA ≈ ci cbj f (xi , yj )
R i=1 j=1
= 1.0360327 · · · .
Therefore
Z Z X7 X
5
log(x + 2y ) dA − ci cbj f (xi , yj ) = 1.546 × 10−5
R i=1 j=1
RR
Example: R log(x + 2y ) dA with n = 7, m = 5
Z Z
log(x + 2y ) dA = 1.0360481 · · ·
R
Z Z 7 X
X 5
log(x + 2y ) dA ≈ ci cbj f (xi , yj )
R i=1 j=1
= 1.0360327 · · · .
Therefore
Z Z X7 X
5
log(x + 2y ) dA − ci cbj f (xi , yj ) = 1.546 × 10−5
R i=1 j=1
R = {(x, y ) | a ≤ x ≤ b, c ≤ y ≤ d. }
Z Z Z b Z d
f (x, y ) dA = f (x, y ) dy dx.
R a c
2 Dimensional Gaussian Quadratures
R = {(x, y ) | a ≤ x ≤ b, c ≤ y ≤ d. }
Z Z Z b Z d
f (x, y ) dA = f (x, y ) dy dx.
R a c
1
a+b b−a c +d d −c
Z
def
gb(u) == f + u, + v dv .
−1 2 2 2 2
RR (b−a)(d−c) R 1
R f (x, y ) dA = 4 −1 g (u)du
b
1
a+b b−a c +d d −c
Z
gb(u) = f + u, + v dv .
−1 2 2 2 2
R1
I n-point Gaussian quadrature for −1 gb(u)du:
Z 1
gb(u)du ≈ c1 gb(u1 ) + c2 gb(u2 ) + · · · + cn gb(un ).
−1
RR (b−a)(d−c) R 1
R f (x, y ) dA = 4 −1 g (u)du
b
1
a+b b−a c +d d −c
Z
gb(u) = f + u, + v dv .
−1 2 2 2 2
R1
I n-point Gaussian quadrature for −1 gb(u)du:
Z 1
gb(u)du ≈ c1 gb(u1 ) + c2 gb(u2 ) + · · · + cn gb(un ).
−1
I For 1 ≤ i ≤ n, let
1
a+b b−a d −c
Z
c +d
xi = + ui , gb(ui ) = f xi , + v dv .
2 2 −1 2 2
RR (b−a)(d−c) R 1
R f (x, y ) dA = 4 −1 g (u)du
b
1
a+b b−a c +d d −c
Z
gb(u) = f + u, + v dv .
−1 2 2 2 2
R1
I n-point Gaussian quadrature for −1 gb(u)du:
Z 1
gb(u)du ≈ c1 gb(u1 ) + c2 gb(u2 ) + · · · + cn gb(un ).
−1
I For 1 ≤ i ≤ n, let
1
a+b b−a d −c
Z
c +d
xi = + ui , gb(ui ) = f xi , + v dv .
2 2 −1 2 2
Z 1
gb(u)du ≈ c1 gb(u1 ) + c2 gb(u2 ) + · · · + cn gb(un )
−1
gb(ui ) ≈ cb1 f (xi , y1 ) + · · · + cbm f (xi , ym ) .
n m
(b − a)(d − c) X X
Z Z
f (x, y ) dA − ci cbj f (xi , yj ) ≈ 6.4×10−10 .
R 4
i=1 j=1
RR
Example: R log(x + 2y ) dA = 1.036 · · · , n = 7, m = 5
I Gaussian quadrature approximation
n m
(b − a)(d − c) X X
Z Z
f (x, y ) dA ≈ ci cbj f (xi , yj ) ≈ 1.03604817065 · · ·
R 4
i=1 j=1
n m
(b − a)(d − c) X X
Z Z
f (x, y ) dA − ci cbj f (xi , yj ) ≈ 6.4×10−10 .
R 4
i=1 j=1
Z Z n X
X m
f (x, y ) dA − ci cbj f (xi , yj ) ≈ 1.5 × 10−5 .
R i=1 j=1
RR
Example: R log(x + 2y ) dA = 1.036 · · · , n = 7, m = 5
I Gaussian quadrature approximation
n m
(b − a)(d − c) X X
Z Z
f (x, y ) dA ≈ ci cbj f (xi , yj ) ≈ 1.03604817065 · · ·
R 4
i=1 j=1
n m
(b − a)(d − c) X X
Z Z
f (x, y ) dA − ci cbj f (xi , yj ) ≈ 6.4×10−10 .
R 4
i=1 j=1
Z Z n X
X m
f (x, y ) dA − ci cbj f (xi , yj ) ≈ 1.5 × 10−5 .
R i=1 j=1
I Gaussian quadrature
Z 1
f (x) dx = c1 f (x1 ) + c2 f (x2 ) + · · · + cn f (xn )
−1
!
4−n f (2n) (ξ)
+O
(2n)!
≈ c1 f (x1 ) + c2 f (x2 ) + · · · + cn f (xn ),
n Quadrature Value
10 2.9758
50 3.1071
250 3.1346
1000 3.1399
R1
Gaussian Quadrature for √ 1
−1 f (x)dx, f (x) = 1−x 2
n Quadrature Value
10 2.9758
50 3.1071
250 3.1346
1000 3.1399
n Quadrature Value
10 2.9758
50 3.1071
250 3.1346
1000 3.1399
π
Z 1 Z
dx x=sinθ 2
√ ==== 1 dθ = 3.1416 · · ·
−1 1 − x2 − π2
R1 f (x)
Improper Integral: −1
√
1−x 2
dx
I Change of variable:
π π
x = sin θ, θ ∈ [− , ].
2 2
I p p
dx = cos θ, 1 − x 2 = 1 − sin2 θ = cos θ.
I New integral becomes proper.
Z 1 Z π
f (x) 2
√ dx = f (sin θ) dθ.
1−x 2
−1 − π2
R1 f (x)
Improper Integral: −1
√
1−x 2
dx
I Change of variable:
π π
x = sin θ, θ ∈ [− , ].
2 2
I p p
dx = cos θ, 1 − x 2 = 1 − sin2 θ = cos θ.
I New integral becomes proper.
Z 1 Z π
f (x) 2
√ dx = f (sin θ) dθ.
1−x 2
−1 − π2
accurate to 15 digits.
Rb g (x)
Improper Integral: a f (x)dx, f (x) = (x−a)p , for p < 1
g 00 (a) g (n)
g (x) = g (a)+g 0 (a)(x−a)+ (x−a)2 +· · ·+ (a)(x−a)n +· · · .
2 n!
I Choose a (k + 1)-term approximation:
x2 x3 x4
P4 (x) = 1 + x + + + .
2 6 24
I
!
1 1 √ x 3/2 x 5/2 x 7/2
Z Z
P4 (x) 1
√ dx = √ + x+ + + dx
0 x 0 x 2 6 24
2 1 1 1
= 2+ + + +
3 5 21 108
≈ 2.9235450.
dz
dx = − .
z2
I Left end improper integral:
1
Z ∞ Z
g (x) a 1
dx = g ( ) z p−2 dz.
a xp 0 z
R∞ sin( x1 )
Example: 1 f (x)dx, f (x) = x 3/2
I Change of variable z = x1 ,:
sin( x1 )
Z ∞ Z 1 Z 1
3/2 −2 sin(z)
3/2
dx = sin(z) z z dz = √ dz.
1 x 0 0 z
R∞ sin( x1 )
Example: 1 f (x)dx, f (x) = x 3/2
I Change of variable z = x1 ,:
sin( x1 )
Z ∞ Z 1 Z 1
3/2 −2 sin(z)
3/2
dx = sin(z) z z dz = √ dz.
1 x 0 0 z
z3
I Choose 5-term Taylor expansion on sin(z): P4 (z) = z − 6.
R∞ sin( x1 )
Example: 1 f (x)dx, f (x) = x 3/2
I Change of variable z = x1 ,:
sin( x1 )
Z ∞ Z 1 Z 1
3/2 −2 sin(z)
3/2
dx = sin(z) z z dz = √ dz.
1 x 0 0 z
z3
I Choose 5-term Taylor expansion on sin(z): P4 (z) = z − 6.
I
z3
Z 1
sin(z)
Z 1
z− z3 sin(z) −
Z z
1 − 6
√ dz 6
√ dz + √
= dz
0 z 0 z 0 z
Z 1 sin(z) − z − z 3
6
≈ 0.61904761 + √ dz.
0 z
I Composite Simpson’s rule with n = 16:
Z 1 sin(z) − z − z 3
6
√ dz ≈ 0.0014890097.
0 z
R∞ sin( x1 )
Example: 1 f (x)dx, f (x) = x 3/2
I
z3
Z 1
sin(z)
Z
z−1 z3 sin(z) −Z z1− 6
√ dz 6
√ dz + √
= dz
0 z 0 z 0 z
Z 1 sin(z) − z − z 3
6
≈ 0.61904761 + √ dz
0 z
≈ 0.61904761 + 0.0014890097
= 0.62053661,
accurate to 8-digit.
Initial Value ODE
I The motion of a swinging pendulum
D = {(t, y ) | 0 ≤ t ≤ T }.
for L = T .
Lipschitz condition
Definition: function f (t, y ) satisfies a Lipschitz condition in the
variable y on a set D ⊂ R2 if a constant L > 0 exists with
D = {(t, y ) | 0 ≤ t ≤ T }.
|f (T , y1 ) − f (T , y2 )|
= T y2 ,
|y1 − y2 |
D = {(t, y ) | 0 ≤ t ≤ T, −Y ≤ y ≤ Y } .
Solution:
∂f ∂f
(t, y ) = 2ty , (t, y ) ≤ 2T Y for all (t, y ) ∈ D.
∂y ∂y