5 - Numerical Diff and Int
5 - Numerical Diff and Int
5 - Numerical Diff and Int
NUMERICAL DIFFERENTIATION/INTEGRATION
NUMERICAL DIFFERENTIATION
𝑓 𝑥0 + ℎ − 𝑓 𝑥0
𝑓′ 𝑥0 = lim .
ℎ→0 ℎ
𝑓 𝑥0 + ℎ − 𝑓 𝑥0
.
ℎ
Numerical Differentiation - Differentiation 4
LAGRANGE POLYNOMIAL
To approximate 𝑓 ′ 𝑥0 , suppose that 𝑥0 ∈ 𝑎, 𝑏 where 𝑓 ∈ 𝐶 2 𝑎, 𝑏
and that 𝑥1 = 𝑥0 + ℎ for some ℎ ≠ 0 that is sufficiently small to ensure
that 𝑥1 ∈ 𝑎, 𝑏 .
𝑓 𝑥0 𝑥 − 𝑥0 − ℎ 𝑓 𝑥0 + ℎ 𝑥 − 𝑥0 𝑓 ′′ 𝛼
𝑓 𝑥 = + + 𝑥 − 𝑥0 𝑥 − 𝑥0 − ℎ
−ℎ ℎ 2
𝑓 𝑥0 𝑓 𝑥0 + ℎ 𝑑 𝑓 ′′ 𝛼
𝑓′ 𝑥 =− + + 𝑥 − 𝑥0 𝑥 − 𝑥0 − ℎ
ℎ ℎ 𝑑𝑥 2
𝑓 𝑥0 + ℎ − 𝑓 𝑥0 𝑑 𝑓 ′′ 𝛼
𝑓′ 𝑥
= + 𝑥 − 𝑥0 𝑥 − 𝑥0 − ℎ
ℎ 𝑑𝑥 2
𝑑 ′′ 𝑥 − 𝑥0 𝑥 − 𝑥0 − ℎ ′′
2 𝑥 − 𝑥0 − ℎ
= 𝑓 𝛼 +𝑓 𝛼
𝑑𝑥 2 2
−ℎ ′′
= 𝑓 𝛼
2
Numerical Differentiation - Differentiation 7
FORWARD/BACKWARD DIFFERENCE
For small values of ℎ, the difference quotient
𝑓 𝑥0 + ℎ − 𝑓 𝑥0
ℎ
𝑀
can be used to approximate 𝑓′
𝑥0 with an error bounded by ℎ
2
where 𝑀 is a bound on 𝑓 ′′ 𝑥 for 𝑥 between 𝑥0 and 𝑥1 = 𝑥0 + ℎ.
𝑓 𝑥 = ln 𝑥
at 𝑥0 = 1.8 using ℎ = 0.1 and determine the bound for the error
approximation.
𝑑 𝑥 − 𝑥0 … 𝑥 − 𝑥𝑛 𝑛+1
𝑥 − 𝑥0 … 𝑥 − 𝑥𝑛 d 𝑛+1
𝑓 𝛼 + 𝑓 𝛼
𝑑𝑥 𝑛+1 ! 𝑛+1 ! dx
𝑥 − 𝑥1 𝑥 − 𝑥2 2𝑥 − 𝑥1 − 𝑥2
𝐿0 𝑥 = 𝐿′0 𝑥 =
𝑥0 − 𝑥1 𝑥0 − 𝑥2 𝑥0 − 𝑥1 𝑥0 − 𝑥2
𝑥 − 𝑥0 𝑥 − 𝑥2 2𝑥 − 𝑥0 − 𝑥2
𝐿1 𝑥 = 𝐿′1 𝑥 =
𝑥1 − 𝑥0 𝑥1 − 𝑥2 𝑥1 − 𝑥0 𝑥1 − 𝑥2
𝑥 − 𝑥0 𝑥 − 𝑥1 2𝑥 − 𝑥0 − 𝑥1
𝐿2 𝑥 = 𝐿′2 𝑥 =
𝑥2 − 𝑥0 𝑥2 − 𝑥1 𝑥2 − 𝑥0 𝑥2 − 𝑥1
𝑥0 , 𝑥1 = 𝑥0 + ℎ, 𝑥2 = 𝑥1 + ℎ = 𝑥0 + 2ℎ
2𝑥 − 𝑥1 − 𝑥2 2𝑥 − 2𝑥0 − 3ℎ
𝐿′0 𝑥 = 𝐿′0 𝑥 =
𝑥0 − 𝑥1 𝑥0 − 𝑥2 2ℎ2
2𝑥 − 𝑥0 − 𝑥2 2𝑥 − 2𝑥0 − 2ℎ
𝐿′1 𝑥 = 𝐿′1 𝑥 =
𝑥1 − 𝑥0 𝑥1 − 𝑥2 −ℎ2
2𝑥 − 𝑥0 − 𝑥1 2𝑥 − 2𝑥0 − ℎ
𝐿′2 𝑥 = 𝐿′2 𝑥 =
𝑥2 − 𝑥0 𝑥2 − 𝑥1 2ℎ2
′
1 1 1 ℎ2 3
𝑓 𝑥0 + ℎ = − 𝑓 𝑥0 + 𝑓 𝑥0 + 2ℎ − 𝑓 𝛼
ℎ 2 2 6
′
1 1 3 ℎ2 3
𝑓 𝑥0 + 2ℎ = 𝑓 𝑥0 − 2𝑓 𝑥0 + ℎ + 𝑓 𝑥0 + 2ℎ + 𝑓 𝛼
ℎ 2 2 3
Numerical Differentiation - Differentiation 15
THREE-POINT FORMULA
With a simple change of variables we get the following
1 ℎ2
𝑓 ′ 𝑥0 = −3𝑓 𝑥0 + 4𝑓 𝑥0 + ℎ − 𝑓 𝑥0 + 2ℎ + 𝑓 3 𝛼
2ℎ 3
1 ℎ2
𝑓 ′ 𝑥0 = −𝑓 𝑥0 − ℎ + 𝑓 𝑥0 + ℎ − 𝑓 3
𝛼
2ℎ 6
1 ℎ2
𝑓 ′ 𝑥0 = 𝑓 𝑥0 − 2ℎ − 4𝑓 𝑥0 − ℎ + 3𝑓 𝑥0 + 𝑓 3 𝛼
2ℎ 3
Numerical Differentiation - Differentiation 16
MIDPOINT AND ENDPOINT FORMULA
Three-Point Endpoint Formula
′
1 ℎ2 3
𝑓 𝑥0 = −3𝑓 𝑥0 + 4𝑓 𝑥0 + ℎ − 𝑓 𝑥0 + 2ℎ + 𝑓 𝛼
2ℎ 3
where 𝛼 lies between 𝑥0 and 𝑥0 + 2ℎ.
′
1 ℎ2 3
𝑓 𝑥0 = −𝑓 𝑥0 − ℎ + 𝑓 𝑥0 + ℎ − 𝑓 𝛼
2ℎ 6
where 𝛼 lies between 𝑥0 − ℎ and 𝑥0 + ℎ.
𝑓 𝑥 = ln 𝑥
at 𝑥0 = 1.8 using ℎ = 0.1 and determine the bound for the error
approximation.
𝑓 𝑥0 − ℎ and 𝑓 𝑥0 + ℎ
we encounter round-off errors
𝑒 𝑥0 − ℎ and 𝑒 𝑥0 + ℎ .
𝑓 𝑥0 − ℎ = 𝑓ሚ 𝑥0 − ℎ + 𝑒 𝑥0 − ℎ
𝑓 𝑥0 + ℎ = 𝑓ሚ 𝑥0 + ℎ + 𝑒 𝑥0 + ℎ
𝑓ሚ 𝑥0 + ℎ − 𝑓ሚ 𝑥0 − ℎ 𝑒 𝑥0 + ℎ − 𝑒 𝑥0 − ℎ ℎ2
𝑓 ′ 𝑥0 − = − 𝑓 3 𝛼
2ℎ 2ℎ 6
Assume that the round off errors are bounded by some number 𝜀 > 0
and that the third derivative of 𝑓 is bounded by a number 𝑀 > 0.
𝑓ሚ 𝑥0 + ℎ − 𝑓ሚ 𝑥0 − ℎ 𝜀 ℎ2
𝑓 ′ 𝑥0 − ≤ + 𝑀
2ℎ ℎ 6
Numerical Differentiation - Differentiation 20
MATH 3800
MATHEMATICAL MODELS AND NUMERICAL METHODS
NUMERICAL QUADRATURE
𝑏
න 𝑓 𝑥 𝑑𝑥
𝑎
is called numerical quadrature.
𝑛 𝑏
𝑎𝑖 𝑓 𝑥𝑖 ≈ න 𝑓 𝑥 𝑑𝑥
𝑖=0 𝑎
𝑃𝑛 𝑥 = 𝑓 𝑥𝑖 𝐿𝑖 𝑥
𝑖=0
𝑛 𝑏 𝑛
1
= 𝑎𝑖 𝑓 𝑥𝑖 + න ෑ 𝑥 − 𝑥𝑖 𝑓 𝑛+1 𝛼 𝑑𝑥
𝑛+1 ! 𝑎
𝑖=0 𝑖=𝑜
where 𝛼 is in 𝑎, 𝑏 and
𝑏
𝑎𝑖 = 𝑖𝐿 𝑎 𝑥 𝑑𝑥, for each 𝑖 = 0, 1, … , 𝑛.
Numerical Quadrature - Integration 24
QUADRATURE FORMULA
The quadrature formula is
𝑏 𝑛
න 𝑓 𝑥 𝑑𝑥 ≈ 𝑎𝑖 𝑓 𝑥𝑖
𝑎 𝑖=0
with error given by
𝑏 𝑛
1 𝑛+1
𝐸 𝑓 = න ෑ 𝑥 − 𝑥𝑖 𝑓 𝛼 𝑑𝑥
𝑛+1 ! 𝑎
𝑖=0
𝑎 = 𝑥0 𝑥1 = 𝑏 𝑥
𝑏 𝑥1
𝑥 − 𝑥1 𝑥 − 𝑥0 1 𝑥1 ′′
න 𝑓 𝑥 𝑑𝑥 = න 𝑓 𝑥𝑜 + 𝑓 𝑥1 𝑑𝑥 + න 𝑓 𝛼 𝑥 − 𝑥0 𝑥 − 𝑥1 𝑑𝑥
𝑎 𝑥0 𝑥0 − 𝑥1 𝑥1 − 𝑥0 2 𝑥0
𝑏 3
𝑥1 − 𝑥0 𝑥1 − 𝑥0
න 𝑓 𝑥 𝑑𝑥 = 𝑓 𝑥0 + 𝑓 𝑥1 − 𝑓 ′′ 𝛼
𝑎 2 12
𝑎 = 𝑥0 𝑥2 = 𝑏 𝑥
𝑏
න 𝑓 𝑥 𝑑𝑥 =
𝑎
𝑥2
𝑥 − 𝑥1 𝑥 − 𝑥2 𝑥 − 𝑥0 𝑥 − 𝑥2 𝑥 − 𝑥0 𝑥 − 𝑥1
න 𝑓 𝑥𝑜 + 𝑓 𝑥1 + 𝑓 𝑥2 𝑑𝑥
𝑥0 𝑥0 − 𝑥1 𝑥0 − 𝑥2 𝑥1 − 𝑥0 𝑥1 − 𝑥2 𝑥2 − 𝑥0 𝑥2 − 𝑥1
1 𝑥2 3
+ න 𝑓 𝛼 𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥2 𝑑𝑥
6 𝑥0
𝑏
ℎ ℎ5 4
න 𝑓 𝑥 𝑑𝑥 = 𝑓 𝑥0 + 4𝑓 𝑥1 + 𝑓 𝑥2 − 𝑓 𝛼
𝑎 3 90
2
න 𝑥 2 𝑑𝑥 .
0
𝑏 3
𝑥1 − 𝑥0
න 𝑓 𝑥 𝑑𝑥 = 𝑥1 − 𝑥0 𝑓 𝑥∗ + 𝑓 ′′ 𝛼
𝑎 24
𝑎 = 𝑥0 𝑎+𝑏 𝑥1 = 𝑏 𝑥
𝑥∗ =
2
2
2 −𝑥 2
න 𝑥 𝑒 𝑑𝑥
0
GAUSSIAN QUADRATURE
න 𝑓 𝑥 𝑑𝑥 ≈ 𝑐𝑖 𝑓 𝑥𝑖
𝑎 𝑖=1
𝑏
𝐼 = න 𝑓 𝑥 𝑑𝑥 ≈ 𝑐1 𝑓 𝑥1 + 𝑐2 𝑓 𝑥2
𝑎
1 1
න 𝑓 𝑥 𝑑𝑥 = න 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2 + 𝑎3 𝑥 3 𝑑𝑥
−1 −1
2 3 4 1
𝑎1 𝑥 𝑎2 𝑥 𝑎3 𝑥
= 𝑎0 𝑥 + + +
2 3 4 −1
2
= 𝑎0 2 + 𝑎1 0 + 𝑎2 + 𝑎3 0
3
1
න 𝑓 𝑥 𝑑𝑥 = 𝑐1 𝑎0 + 𝑎1 𝑥1 + 𝑎2 𝑥12 + 𝑎3 𝑥13 + 𝑐2 𝑎0 + 𝑎1 𝑥2 + 𝑎2 𝑥22 + 𝑎3 𝑥23
−1
A little algebra show that this system of equations has the unique
solution
𝑐1 = 1 𝑐2 = 1
3 3
𝑥1 = − 𝑥2 =
3 3
Gaussian Quadrature - Gaussian Quadrature 40
BASIS OF THE GAUSSIAN QUADRATURE
The two point Gaussian quadrature rule gives the approximation
1
3 3
න 𝑓 𝑥 𝑑𝑥 ≈ 𝑓 − +𝑓 .
−1 3 3
NOTE This formula produces the exact result for every polynomial of
degree three or less.
1
𝑃0 𝑥 = 1 𝑃1 𝑥 = 𝑥 𝑃2 𝑥 = 𝑥2 −
3
3
3
6 2 3
4
𝑃3 𝑥 = 𝑥 − 𝑥 and 𝑃4 𝑥 = 𝑥 − 𝑥 +
5 7 35
The roots of these polynomials are distinct, lie in the interval −1, 1 ,
have symmetry with respect to the origin, and are the correct choices
for determining the parameters that give us the nodes and coefficients
for our quadrature method.
Gaussian Quadrature - Gaussian Quadrature 43
THEOREM
Suppose that 𝑥1 , … , 𝑥𝑛 are the roots of the 𝑛th Legendre polynomial 𝑃𝑛 𝑥
and for each 𝑖 = 1, … , 𝑛, the numbers 𝑐𝑖 are defined by
1 𝑛
𝑥 − 𝑥𝑗
𝑐𝑖 = න ෑ 𝑑𝑥
𝑥𝑖 − 𝑥𝑗
−1 𝑗=1
𝑗≠𝑖
1
න 𝑒 𝑥 cos 𝑥 𝑑𝑥
−1
𝑏
𝑏−𝑎 1 1 1
න 𝑔 𝑥 𝑑𝑥 = න 𝑔 𝑏−𝑎 𝑡+𝑎+𝑏 𝑑𝑡 = න 𝑓 𝑡 𝑑𝑡
𝑎 2 −1 2 −1
𝜋
න sin 𝑥 𝑑𝑥
0