CVE 154 Lesson 3 Truncation Error and Taylor Series
CVE 154 Lesson 3 Truncation Error and Taylor Series
CVE 154 Lesson 3 Truncation Error and Taylor Series
LESSON 3:
TRUNCATION ERROR
AND TAYLOR SERIES
TAYLOR SERIES
The Taylor series provides a means to predict a function value at one point,
𝑥𝑖:1 , in terms of the function value and its derivatives at another point, 𝑥𝑖 . In
particular, the theorem states that any smooth function can be approximated
as a polynomial.
𝑓 ′′ 𝑥
𝑖
𝑓 𝑥𝑖:1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 𝑥𝑖:1 − 𝑥𝑖 + 𝑥𝑖:1 − 𝑥𝑖 2
2!
𝑓 ′′′ 𝑥𝑖 𝑓 (𝑛) (𝑥 )
𝑖
+ 𝑥𝑖:1 − 𝑥𝑖 3 +· · · + 𝑥𝑖:1 − 𝑥𝑖 𝑛 + 𝑅𝑛
3! 𝑛!
A remainder term 𝑅𝑛 is included to account for all terms from n+1 to infinity:
𝑓 𝑛:1𝜉
𝑅𝑛 = 𝑥𝑖:1 − 𝑥𝑖 𝑛:1
𝑛+1 !
where the subscript 𝑛 connotes that this is the remainder for the nth-order
approximation and 𝜉 is a value of 𝑥 that lies somewhere between 𝑥𝑖 and 𝑥𝑖:1 .
This remainder term provides the exact value of the error.
TAYLOR SERIES
If we define a step size ℎ = 𝑥𝑖:1 − 𝑥𝑖 , we can express the Taylor series as:
𝑓 ′′ 𝑥 𝑓 ′′′ 𝑥 𝑓 𝑛 (𝑥 )
𝑖 𝑖 𝑖
𝑓 𝑥𝑖:1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + ℎ2 + ℎ3 +· · · + ℎ𝑛 + 𝑅𝑛
2! 3! 𝑛!
where the remainder term is:
𝑓 𝑛:1𝜉 𝑛:1
𝑅𝑛 = ℎ
𝑛+1 !
NOTE:
𝑓 𝑥𝑖:1 = 𝑓 𝑥𝑖 zero-order approximation
+
𝑓′′′ 0
ℎ + 3 𝑓4 0
ℎ4
Taylor series being equal to zero, as indicated.
3! 4!
;1 2
Therefore, the Taylor series expansion to the
𝑓 1 ≅ 1.2 + −0.25 1 + 1 fourth derivative yields an exact estimate at
2!
;0.90 3 ;2.4 4 𝑥𝑖:1 = 1 :
+ 1 + 1
3! 4!
2 3 4
𝑓 1 ≅ 0.20 𝑓 1 = 1.2 − 0.25 1 − 0.5 1 − 0.15 1 − 0.1 1
𝐸𝑡 = 0.2 − 0.20 = 0 𝑓 1 = 0.2
TAYLOR SERIES
In general, the nth-order Taylor series expansion will be exact for an nth-order
polynomial.
For other differentiable and continuous functions, such as exponentials and
sinusoids, a finite number of terms will not yield an exact estimate. Each
additional term will contribute some improvement, however slight, to the
approximation. Only if an infinite number of terms are added will the series
yield an exact result.
The practical value of Taylor series expansions is that, in most cases, the
inclusion of only a few terms will result in an approximation that is close enough
to the true value for practical purposes. The assessment of how many terms are
required to get “close enough” is based on the remainder term of the
expansion.
SAMPLE PROBLEM
EXAMPLE 2: a. Zero-order Taylor series approx. 𝑛 = 0
𝑓 𝑥𝑖:1 ≅ 𝑓 𝑥𝑖
Use Taylor series expansions with 𝑛 = 0
𝜋 𝜋 𝜋
to 6 to approximate function 𝑓
3
≅ 𝑓
4
≅ cos
4
= 0.707106781
𝑓 𝑥 = cos 𝑥 ε𝑡 =
0.5;0.707106781
100% = −41.4%
𝜋 0.5
at 𝑥𝑖:1 = on the basis of the value of
3 b. First-order Taylor series approx. 𝑛 = 1
𝜋
𝑓 𝑥 and its derivatives at 𝑥𝑖 = . Note 𝑓 𝑥𝑖:1 ≅ 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ
4
that this means that
Solving the first derivative of 𝑓 𝑥 :
𝜋 𝜋 𝜋
ℎ= − = 𝑓′ 𝑥 = − sin 𝑥
3 4 12
𝜋
Note: Set your calculator to radians for Evaluate this with 𝑥 = 4 :
computations. 𝜋 𝜋
𝑓′ = − sin = −0.707106781
4 4
SOLUTION: Solving the first-order Taylor series:
Since the function is known, we can 𝑓
𝜋
=𝑓
𝜋
+ 𝑓′
𝜋
ℎ
3 4 4
compute the target true value for 𝑓 𝑥 at 𝜋 𝜋 𝜋 𝜋
𝜋 𝑓 = cos + − sin = 0.521986658
𝑥𝑖:1 = 3 . 3 4 4 12
𝜋 𝜋 0.5;0.521986658
𝑓 = cos = 0.5 ε𝑡 = 100% = −4.40%
0.5
3 3
SAMPLE PROBLEM
c. Second-order Taylor series approx. 𝑛 = 2 We can see that the inclusion of additional
′ 𝑓′′ 𝑥𝑖 2 terms results in an improved estimate.
𝑓 𝑥𝑖:1 ≅ 𝑓 𝑥𝑖 + 𝑓 𝑥𝑖 ℎ + ℎ
2!
Solving the second derivative of 𝑓 𝑥 : To speed up the process, we will use MS Excel
and the results are shown in the next slide.
𝑓′′ 𝑥 = − cos 𝑥
Evaluate this with 𝑥 = 4 :
𝜋 Notice that the derivatives never go to zero as
was the case with the polynomial in the
𝜋
𝑓′′ 0 = − cos = −0.707106781 previous sample problem. Therefore, each
4
Solving the second-order Taylor series: additional term results in some improvement
𝜋 in the estimate.
𝜋 𝜋 𝜋 𝑓′′
𝑓 ≅𝑓 + 𝑓′ ℎ+ 4
ℎ2
3 4 4 2! However, also notice how most of the
𝜋
𝜋 𝜋 𝜋 𝜋 ; cos
4 𝜋 2 improvement comes with the initial terms.
𝑓 ≅ cos + − sin +
3 4 4 12 2! 12 For this case, by the time we have added the
𝜋
𝑓 ≅ 0.497754491 third-order term, the error is reduced to
3
0.5;0.497754491 2.62× 10;2 %, which means that we have
ε𝑡 = 100% = 0.449%
0.5 attained 99.9738% of the true value.
SAMPLE PROBLEM
TAYLOR SERIES PROBLEM
′
𝑓 ′′ 𝑥𝑖 2 𝑓 ′′′ 𝑥𝑖 3 𝑓 𝑛 (𝑥𝑖 ) 𝑛
𝑓 𝑥𝑖:1 = 𝑓 𝑥𝑖 + 𝑓 𝑥𝑖 ℎ + ℎ + ℎ +· · · + ℎ + 𝑅𝑛
2! 3! 𝑛!
𝑓 𝑥 = cos 𝑥
𝜋
xi = 0.785398163 4
𝜋
xi+1 = 1.047197551 3
𝜋
h= 0.261799388 12
Notice that the first-order Taylor series approximation is what we used as the
formula for the first derivative in the parachutist problem in Lesson 1:
ESTIMATING TRUNCATIONS ERRORS
Solving for the truncation error using the remainder formula (𝑛 = 1):
𝑣 𝑛:1 𝜉 𝑛:1
𝑅1 ℎ
𝑡𝑟𝑢𝑛𝑐𝑎𝑡𝑖𝑜𝑛 𝑛+1 !
= = 𝑤ℎ𝑒𝑟𝑒 ℎ = 𝑡𝑖:1 − 𝑡𝑖
𝑒𝑟𝑟𝑜𝑟 𝑡𝑖:1 − 𝑡𝑖 𝑡𝑖:1 − 𝑡𝑖
2
𝑣 𝜉 2
𝑅1 𝑡𝑖:1 − 𝑡𝑖
2 !
=
𝑡𝑖:1 − 𝑡𝑖 𝑡𝑖:1 − 𝑡𝑖
𝑅1 𝑣 ′′ 𝜉
= 𝑡𝑖:1 − 𝑡𝑖
𝑡𝑖:1 − 𝑡𝑖 2 !
𝑅1
= 𝑂 𝑡𝑖:1 − 𝑡𝑖 = 𝑂 ℎ
𝑡𝑖:1 − 𝑡𝑖
Thus, the truncation error is of order 𝑡𝑖:1 − 𝑡𝑖 . This means that the
truncation error of our derivative approximation should be proportional to the
step size. Consequently, if we halve the step size, we would expect to halve the
error of the derivative.
SAMPLE PROBLEM
EXAMPLE 3:
The figure below is a plot of the function
𝑓 𝑥 = 𝑥𝑚
for 𝑚 = 1, 2, 3 and 4 over the range
from 𝑥 = 1 to 2. Notice that for 𝑚 = 1
the function is linear, and as 𝑚 increases,
more curvature or nonlinearity is
introduced into the function.
Employ the first-order Taylor series to
approximate this function for various
values of the exponent 𝑚 and the step
size ℎ.
SAMPLE PROBLEM
SOLUTION: Note that since 𝑚 = 1, the function is a
a. First, we explore the effect of different polynomial of the first degree (linear).
values of 𝑚 to the remainder. Hence, the second and higher derivatives of
the function is equal to zero. So our
The first-order Taylor Series approximation remainder is:
is: 𝑅1 = 0 + 0 + 0 + ⋯ = 0
𝑓 𝑥𝑖:1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ
Therefore, the first-order Taylor series
𝑓 𝑥𝑖:1 = 𝑥𝑖 𝑚 + 𝑚𝑥𝑖 𝑚;1 ℎ expansion gives an exact value when the
The remainder of the series is: function is linear.
𝑓 ′′ 𝑥𝑖 2 𝑓 ′′′ 𝑥𝑖 3 For 𝑚 = 2: true value 𝑓 2 = 2 2
=4
𝑅1 = ℎ + ℎ +· · ·
2! 3! 2 2;1
𝑓 2 = 1 + 2 1 1 =3
Note that 𝑥𝑖:1 = 2 and 𝑥𝑖 = 1. Solving for
the step size 𝑓 ′′ 𝑥 = 𝑚 𝑚 − 1 𝑥 𝑚;2
ℎ =2−1=1 𝑓 ′′ 1 = 2 2 − 1 1 2;2
=2
For 𝑚 = 1: true value 𝑓 2 = 2 1 =2 2 2
𝑅1 = 1 +0+0+⋯=1
𝑓 2 = 1 1 + 1 1 1;1 1 =2 2!
SAMPLE PROBLEM
For 𝑚 = 3: true value 𝑓 2 = 2 3 =8 4
𝑓 𝑥 = 𝑚 𝑚 − 1 𝑚 − 2 𝑚 − 3 𝑥 𝑚;4
3 3;1
𝑓 2 = 1 + 3 1 1 =4 4 4;4
𝑓 1 =4 4−1 4−2 4−3 1 = 24
𝑓 ′′ 𝑥 = 𝑚 𝑚 − 1 𝑥 𝑚;2 12 24 24
2 3 4
′′ 3;2 𝑅1 = 1 + 1 + 1 +0+⋯
𝑓 1 =3 3−1 1 =6 2! 3! 4!
𝑓 ′′′ 𝑥 = 𝑚 𝑚 − 1 𝑚 − 2 𝑥 𝑚;3 = 11
𝑓 ′′′ 1 = 3 3 − 1 3 − 2 1 3;3
=6 From the results, we can see that the error
6 6 𝑅1 increases as the function becomes more
2 3
𝑅1 = 1 + 1 +0+0+⋯=4 nonlinear (𝑚 increases).
2! 3!
For 𝑚 = 4: true value 𝑓 2 = 2 4 = 16 b. Now, we explore what happens to the
remainder when the step size is changed.
4 4;1
𝑓 2 = 1 + 4 1 1 =5
The first-order Taylor Series approximation
𝑓 ′′ 𝑥 = 𝑚 𝑚 − 1 𝑥 𝑚;2 is:
𝑓 ′′ 1 = 4 4 − 1 1 4;2
= 12 𝑓 𝑥𝑖:1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ
𝑓 ′′′ 𝑥 = 𝑚 𝑚 − 1 𝑚 − 2 𝑥 𝑚;3 𝑓 𝑥𝑖:1 = 𝑥𝑖 𝑚 + 𝑚𝑥𝑖 𝑚;1 ℎ
𝑓 ′′′ 1 = 4 4 − 1 4 − 2 1 4;3
= 24
SAMPLE PROBLEM
Let us modify the function for when The remainder term is:
𝑚 = 4 with 𝑥𝑖:1 = 𝑥𝑖 + ℎ and 𝑥𝑖 = 1. 12 2 24 3 24 4
𝑅1 = ℎ + ℎ + ℎ +0+0+⋯
4 4;1 ℎ 2! 3! 4!
𝑓 𝑥𝑖 + ℎ = 1 +4 1
𝑅1 = 6ℎ2 + 4ℎ3 + ℎ4
𝑓 𝑥𝑖 + ℎ = 1 + 4ℎ
We will use MS Excel to evaluate the function using different values of the step size ℎ.
True Percent
Step Size True Value First Order Remainder
Relative Error
h f(xi + h) Approximation R1
εt (%)
1.000000 16.000000 5.000000 11.000000 68.75
0.500000 5.062500 3.000000 2.062500 40.74
0.250000 2.441406 2.000000 0.441406 18.08
0.125000 1.601807 1.500000 0.101807 6.36
0.062500 1.274429 1.250000 0.024429 1.92
0.031250 1.130982 1.125000 0.005982 0.53
0.015625 1.063980 1.062500 0.001480 0.14
From the table, we can conclude that the error will decrease as the step size ℎ is decreased.
SAMPLE PROBLEM
Summary:
Therefore, we conclude that the error of the first-order Taylor series
approximation decreases as 𝑚 approaches 1 (function is linear) and as ℎ
decreases.
For real world problems, we cannot choose the degree of the function we want
to solve. It is dependent on the mathematical model of the situation. Hence,
decreasing the step size is our solution to decrease errors.
NUMERICAL DIFFERENTIATION
FORWARD DIFFERENCE APPROXIMATION OF THE FIRST DERIVATIVE:
Also called finite divided difference as a numerical method
′
𝑓 𝑥𝑖:1 − 𝑓 𝑥𝑖
𝑓 𝑥𝑖 = + 𝑂 𝑥𝑖:1 − 𝑥𝑖
𝑥𝑖:1 − 𝑥𝑖
or
Δ𝑓𝑖
𝑓′ 𝑥𝑖 = +𝑂 ℎ
ℎ
where:
Δ𝑓𝑖 – is referred to as the first
forward difference
ℎ – is called the step size
Δ𝑓𝑖
– is referred to as a first finite
ℎ
divided difference
𝑂 ℎ – error
NUMERICAL DIFFERENTIATION
BACKWARD DIFFERENCE APPROXIMATION OF THE FIRST DERIVATIVE:
The Taylor series can be expanded backward to calculate a previous value on the
basis of a present value. Note that ℎ = 𝑠𝑡𝑒𝑝 𝑠𝑖𝑧𝑒.
𝑓 ′′ 𝑥 𝑓 ′′′ 𝑥
𝑖 𝑖
𝑓 𝑥𝑖;1 = 𝑓 𝑥𝑖 − 𝑓 ′ 𝑥𝑖 ℎ + ℎ2 − ℎ3 +· · ·
2! 3!
Truncating this equation after the first
derivative yields
𝑓 𝑥𝑖;1 = 𝑓 𝑥𝑖 − 𝑓 ′ 𝑥𝑖 ℎ + 𝑅1
′
𝑓 𝑥𝑖 − 𝑓 𝑥𝑖;1 𝑅1
𝑓 𝑥𝑖 = +
ℎ ℎ
′
𝛻𝑓𝑖
𝑓 𝑥𝑖 = +𝑂 ℎ
ℎ
where:
𝛻𝑓𝑖 – is referred to as the first
backward difference
𝑂 ℎ – error
NUMERICAL DIFFERENTIATION
CENTERED DIFFERENCE APPROXIMATION OF THE FIRST DERIVATIVE:
A third way to approximate the first derivative is to subtract backward Taylor
series expansion form the forward Taylor series expansion:
𝑓 ′′ 𝑥 𝑓 ′′′ 𝑥
𝑖 𝑖
𝑓 𝑥𝑖:1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + ℎ2 + ℎ3 + · · ·
2! 3!
′′ ′′′
′
𝑓 𝑥𝑖 2
𝑓 𝑥𝑖 3
𝑓 𝑥𝑖;1 = 𝑓 𝑥𝑖 − 𝑓 𝑥𝑖 ℎ + ℎ − ℎ +···
2! 3!
′
2𝑓 ′′′ 𝑥𝑖 3
𝑓 𝑥𝑖:1 − 𝑓 𝑥𝑖;1 = 2𝑓 𝑥𝑖 ℎ + ℎ +···
3!
Solving for the first derivative:
2𝑓 ′′′ 𝑥
𝑖
2𝑓 ′ 𝑥𝑖 ℎ = 𝑓 𝑥𝑖:1 − 𝑓 𝑥𝑖;1 − ℎ3 − · · ·
6
𝑓 𝑥 − 𝑓 𝑥 2𝑓 ′′′ 𝑥
𝑖:1 𝑖;1 𝑖
𝑓 ′ 𝑥𝑖 = − ℎ3 − · · ·
2ℎ 12ℎ
NUMERICAL DIFFERENTIATION
The equation for central difference approximation of the first derivative is:
𝑓 𝑥𝑖:1 − 𝑓 𝑥𝑖;1
𝑓′ 𝑥𝑖 = − 𝑂 ℎ2
2ℎ
𝑓 𝑥𝑖 − 2𝑓 𝑥𝑖;1 + 𝑓 𝑥𝑖;2
𝑓 ′′ 𝑥𝑖 = +𝑂 ℎ
ℎ2
𝑓 𝑥𝑖:1 − 2𝑓 𝑥𝑖 + 𝑓 𝑥𝑖;1
𝑓 ′′ 𝑥𝑖 = + 𝑂 ℎ 2
ℎ2
REFERENCE
Chapra, S. C., & Canale, R. P. (2010). Numerical Methods for
Engineers (6th Edition). McGraw-Hill.
THE END