Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

CVE 154 – Statics of Rigid Bodies

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

𝑓 𝑥𝑖:1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ first-order approximation


𝑓 ′′ 𝑥
𝑖
𝑓 𝑥𝑖:1 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + ℎ2 second-order approximation
2!

𝑓 ′′ 𝑥𝑖 2 𝑓 ′′′ 𝑥𝑖 3 third-order approximation
𝑓 𝑥𝑖:1 = 𝑓 𝑥𝑖 + 𝑓 𝑥𝑖 ℎ + ℎ + ℎ
2! 3!
TAYLOR SERIES
 The graph below shows the zero-, first-, and second-order Taylor Series
approximation of the true curve of a function 𝑓 𝑥 between 𝑥𝑖 and 𝑥𝑖:1 .
SAMPLE PROBLEM
EXAMPLE 1: This means that the function starts at
𝑓 0 = 1.2 and then curves downward to
Use zero- through fourth-order Taylor series 𝑓 1 = 0.2. Thus, the true value that we are
expansions to approximate the function trying to predict is 0.2.
𝑓 𝑥 = −0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 − 0.25𝑥 + 1.2
a. Zero-order Taylor series approx. 𝑛 = 0
from 𝑥𝑖 = 0 with ℎ = 1. That is, predict
𝑓 𝑥𝑖:1 ≅ 𝑓 𝑥𝑖
the function’s value at 𝑥𝑖:1 = 1.
𝑓 1 ≅ 𝑓 0 ≅ 1.2
SOLUTION: 𝐸𝑡 = 0.2 − 1.2 = −1

Since the function is known, we can b. First-order Taylor series approx. 𝑛 = 1


compute values for 𝑓 𝑥 between 0 and 1. 𝑓 𝑥𝑖:1 ≅ 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ
If 𝑥 = 0 : Solving the first derivative of 𝑓 𝑥 :
𝑓 0 = −0.1 0 4 − 0.15 0 3
− 0.5 0 2
𝑓′ 𝑥 = −0.4𝑥 3 − 0.45𝑥 2 − 1.0𝑥 − 0.25
−0.25 0 + 1.2
𝑓 0 = 1.2 Evaluate this with 𝑥 = 0:
3 2
If 𝑥 = 1 : 𝑓′ 0 = −0.4 0 − 0.45 0 − 1.0 0 − 0.25
𝑓 1 = −0.1 1 4 − 0.15 1 3
− 0.5 1 2
𝑓′ 0 = −0.25
−0.25 1 + 1.2
𝑓 1 = 0.2
SAMPLE PROBLEM
Solving the first-order Taylor series: d. Third-order Taylor series approx. 𝑛 = 3
𝑓 1 ≅ 𝑓 0 + 𝑓′ 0 ℎ 𝑓 𝑥𝑖:1 ≅ 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ +
𝑓′′ 𝑥𝑖
ℎ2
2!
𝑓 1 ≅ 1.2 + −0.25 1 = 0.95
𝑓′′′ 𝑥𝑖
𝐸𝑡 = 0.2 − 0.95 = −0.75 + ℎ3
3!
Solving the third derivative of 𝑓 𝑥 :
c. Second-order Taylor series approx. 𝑛 = 2
𝑓′′ 𝑥𝑖
𝑓′′′ 𝑥 = −2.4𝑥 − 0.90
′ 2
𝑓 𝑥𝑖:1 ≅ 𝑓 𝑥𝑖 + 𝑓 𝑥𝑖 ℎ + ℎ
2! Evaluate this with 𝑥 = 0:
Solving the second derivative of 𝑓 𝑥 : 𝑓 ′′′ 0 = −2.4 0 − 0.90 = −0.90
𝑓′′ 𝑥 = −1.2𝑥 2 − 0.90𝑥 − 1.0 Solving the third-order Taylor series:
Evaluate this with 𝑥 = 0: 𝑓 ′′ 0 2 𝑓′′′ 0 3
2
𝑓 1 ≅ 𝑓 0 + 𝑓′ 0 ℎ + ℎ + ℎ
𝑓′′ 0 = −1.2 0 − 0.90 0 − 1.0 2! 3!
;1 ;0.90
𝑓′′ 0 = −1.0 𝑓 1 ≅ 1.2 + −0.25 1 + 1 2+ 1 3
2! 3!

Solving the second-order Taylor series: 𝑓 1 ≅ 0.30


𝑓′′ 0 2 𝐸𝑡 = 0.2 − 0.30 = −0.10
𝑓 1 ≅ 𝑓 0 + 𝑓′ 0 ℎ + ℎ
2!
;1
𝑓 1 ≅ 1.2 + −0.25 1 + 1 2
2!
𝑓 1 ≅ 0.45
𝐸𝑡 = 0.2 − 0.45 = −0.25
SAMPLE PROBLEM
e. Fourth-order Taylor series approx. 𝑛 = 4 This means that the remainder at 𝑛 = 4 is:
𝑓′′ 𝑥𝑖 𝑓 5
𝜉 5
𝑓 𝑥𝑖:1 ≅ 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + ℎ2 𝑅4 = ℎ = 𝐸𝑡 = 0
2!
5 !
𝑓′′′ 𝑥𝑖 3 𝑓 4 𝑥𝑖
+ ℎ + ℎ4
3! 4! If we simplify the fourth-order Taylor series
Solving the fourth derivative of 𝑓 𝑥 : approximation we get:
4
𝑓 𝑥 = −2.4 𝑓 𝑥 = 1.2 − 0.25ℎ − 0.5ℎ2 − 0.15ℎ3 − 0.1ℎ4
Evaluate this with 𝑥 = 0: This is similar to the equation we started with.
4
𝑓 0 = −2.4 This is because our starting equation is a fourth-
Solving the fourth-order Taylor series: order polynomial. Hence, the fifth and higher
′ 𝑓′′ 0 derivatives of that polynomial is zero. This
𝑓 1 ≅𝑓 0 +𝑓 0 ℎ+ ℎ2 results to the remainder term of the fourth-order
2!

+
𝑓′′′ 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

f(xi+1) = 0.5 True Value

Formula of N-th Value of N-th True Relative


Approximation
Order n Derivative of f(x) Derivative of f(x) Percent Error
f(xi+1)
f(n)(x) f(n)(x) εt (%)
0 cos x 0.707106781 0.707106781 -4.14E+01
1 − sin x -0.707106781 0.521986659 -4.40E+00
2 − cos x -0.707106781 0.497754491 4.49E-01
3 sin x 0.707106781 0.499869147 2.62E-02
4 cos x 0.707106781 0.500007551 -1.51E-03
5 − sin x -0.707106781 0.500000304 -6.08E-05
6 − cos x -0.707106781 0.499999988 2.44E-06
REMAINDER OF THE
TAYLOR SERIES EXPANSION
 We now examine the remainder term of the Taylor series to explain why we
included the argument 𝜉 (lower case Greek letter xi ).
 In mathematics, the mean value theorem states, roughly, that for a given
planar arc between two endpoints, there is at least one point at which the
tangent to the arc is parallel to the secant through its endpoints.
 More precisely, the theorem states that if
𝑓 is a continuous function on the closed
interval 𝑎, 𝑏 and differentiable on the
open interval 𝑎, 𝑏 , then there exists a
point 𝑐 in 𝑎, 𝑏 such that the tangent at 𝑐
is parallel to the secant line through the
endpoints 𝑎, 𝑓 𝑎 and 𝑏, 𝑓 𝑏 , that is,
𝑓 𝑏 −𝑓 𝑎
𝑓′ 𝑐 =
𝑏−𝑎 a 𝜉 b
Slope of the secant line connecting the end points
Slope of the tangent line at point c
REMAINDER OF THE
TAYLOR SERIES EXPANSION
 If we apply the mean value theorem to our situation where the point 𝑎 = 𝑥𝑖 ,
𝑏 = 𝑥𝑖:1 , and 𝑐 = 𝜉. Then equating the slopes of the two parallel lines, we get:
𝑅0
𝑓′ 𝜉 =

which can be rearranged into:
𝑅0 = 𝑓 ′ 𝜉 ℎ
 This is the remainder for the
zero-order Taylor series.
 The remainder of higher-
order Taylor series would just
be a modification of this.
𝑛:1
𝑓 𝜉 𝑛:1
𝑅𝑛 = ℎ
𝑛+1 !
ESTIMATING TRUNCATIONS ERRORS
 If we apply the Taylor series to the falling parachutist problem in Lesson 1, we
should get

𝑣 ′′ 𝑡𝑖
𝑣 𝑡𝑖:1 = 𝑣 𝑡𝑖 + 𝑣 𝑡𝑖 𝑡𝑖:1 − 𝑡𝑖 + 𝑡𝑖:1 − 𝑡𝑖 2 + · · · + 𝑅𝑛
2!
 If we truncate the series up to the first derivative term 𝑛 = 1:
𝑣 𝑡𝑖:1 = 𝑣 𝑡𝑖 + 𝑣 ′ 𝑡𝑖 𝑡𝑖:1 − 𝑡𝑖 + 𝑅1
 Solving for the first derivative to see the similarity with the finite divided
difference method that we used in Lesson 1:
𝑣 𝑡𝑖:1 − 𝑣 𝑡𝑖 𝑅1
𝑣′ 𝑡𝑖 = −
𝑡𝑖:1 − 𝑡𝑖 𝑡𝑖:1 − 𝑡𝑖

First-order approximation Truncation error

 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ℎ

 Notice that the truncation error is


of the order of ℎ2 in contrast to
the forward and backward
approximations that were of the
order of ℎ.
 Therefore, the centered
difference approximation is a
more accurate representation of
the derivative.
SAMPLE PROBLEM
EXAMPLE 4: SOLUTION:
Use forward and backward difference a. For ℎ = 0.5 , the function can be
approximations of 𝑂(ℎ) and a centered employed to determine
difference approximation of 𝑂(ℎ2 ) to When 𝑥𝑖;1 = 0.5 − 0.5 = 0:
estimate the first derivative of 4 3 2
𝑓 0 = − 0.1 0 − 0.15 0 − 0.5 0
𝑓(𝑥) = − 0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 −0.25(0) + 1.2
− 0.25𝑥 + 1.2
𝑓 0 = 1.2
at 𝑥 = 0.5 using a step size ℎ = 0.5 .
Repeat the computation using ℎ = 0.25. When 𝑥𝑖 = 0.5:
Note that the derivative can be calculated 𝑓 0.5 = − 0.1 0.5 4
− 0.15 0.5 3
− 0.5 0.5 2
directly as −0.25(0.5) + 1.2
′ 3 2
𝑓 (𝑥) = − 0.4𝑥 − 0.45𝑥 − 1.0𝑥 − 0.25
𝑓(0.5) = 0.925
and can be used to compute the true value
′ 3 2
When 𝑥𝑖:1 = 0.5 + 0.5 = 1.0:
𝑓 0.5 = − 0.4 0.5 − 0.45 0.5 4 3 2
𝑓 1 = − 0.1 1 − 0.15 1 − 0.5 1
− 1.0 0.5 − 0.25
−0.25(1) + 1.2
𝑓 ′ 0.5 = −0.9125
𝑓(1) = 0.2
SAMPLE PROBLEM
The forward divided difference of the first b. For ℎ = 0.25 , the function can be
derivative is: employed to determine
𝑓 1 ;𝑓(0.5) 0.2;0.925 When 𝑥𝑖;1 = 0.5 − 0.25 = 0.25:
𝑓 ′ 0.5 = = = −1.45
ℎ 0.5
4
−0.9125 − −1.45 𝑓 0.25 = − 0.1 0.25 − 0.15 0.25 3
𝜀𝑡 = 100% = 58.9% 2
−0.9125 − 0.5 0.25 − 0.25(0.25) + 1.2
𝑓 0.25 = 1.103515625
The backward divided difference of the first
derivative is: When 𝑥𝑖 = 0.5:
𝑓 0.5 − 𝑓(0) 0.925 − 1.2 4 3 2
𝑓 ′ 0.5 = = = −0.55 𝑓 0.5 = − 0.1 0.5 − 0.15 0.5 − 0.5 0.5
ℎ 0.5
−0.9125 − −0.55 −0.25(0.5) + 1.2
𝜀𝑡 = 100% = 39.7%
−0.9125 𝑓(0.5) = 0.925
The centered divided difference of the first When 𝑥𝑖:1 = 0.5 + 0.25 = 0.75:
derivative is: 𝑓 0.75 = − 0.1 0.75 4
− 0.15 0.75 3
𝑓 1 − 𝑓(0) 0.925 − 1.2 2
− 0.5 0.75 − 0.25 0.75 + 1.2
𝑓 ′ 0.5 = = = −1
2ℎ 2 0.5
𝑓(0.75) = 0.636328125
−0.9125 − −1
𝜀𝑡 = 100% = 9.59%
−0.9125
SAMPLE PROBLEM
The forward divided difference of the first −0.9125 − −0.934375
𝜀𝑡 = 100% = 2.40%
derivative is: −0.9125
𝑓 0.75 ;𝑓(0.5) 0.636328125;0.925
𝑓 ′ 0.5 = =
ℎ 0.25
= −1.1546875 For both step sizes, the centered difference
−0.9125 − −1.1546875 approximation is more accurate than
𝜀𝑡 = 100% = 26.5% forward or backward differences.
−0.9125

The backward divided difference of the first


derivative is: Also, as predicted by the Taylor series
𝑓 0.5 − 𝑓(0.25) 0.925 − 1.103515625 analysis, halving the step size approximately
𝑓 ′ 0.5 = =
ℎ 0.25 halves the error of the backward and
= −0.7140625 forward differences and quarters the error of
−0.9125 − −0.7140625 the centered difference.
𝜀𝑡 = 100% = 21.7%
−0.9125

The centered divided difference of the first


derivative is:
𝑓 0.75 − 𝑓(0.25)
𝑓 ′ 0.5 =
2ℎ
0.636328125;1.103515625
= = −0.934375
2 0.25
NUMERICAL DIFFERENTIATION
FORWARD DIFFERENCE APPROXIMATION OF HIGHER DERIVATIVE:
 Use Taylor series expansion with prediction point at 𝑥𝑖:2 :
′′ ′′′
𝑓 𝑥 𝑖 𝑓 𝑥𝑖
𝑓 𝑥𝑖:2 = 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 2ℎ + 2ℎ 2 + 2ℎ 3 + · · ·
2! 3!
′′ ′′′
′ 𝑥 ℎ+
𝑓 𝑥𝑖 2+
𝑓 𝑥𝑖 3
2{ 𝑓 𝑥 𝑖:1 = 𝑓 𝑥𝑖 + 𝑓 𝑖
2!

3!
ℎ +··· }
2𝑓 ′′ 𝑥𝑖 2 6𝑓 ′′′ 𝑥𝑖 3
𝑓 𝑥𝑖:2 − 2𝑓 𝑥𝑖:1 = −𝑓 𝑥𝑖 + ℎ + ℎ +···
2! 3!
Solving for the second derivative:
𝑓 ′′ 𝑥𝑖 ℎ2 = 𝑓 𝑥𝑖:2 − 2𝑓 𝑥𝑖:1 + 𝑓 𝑥𝑖 − 𝑓 ′′′ 𝑥𝑖 ℎ3 · · ·
𝑓 𝑥𝑖:2 − 2𝑓 𝑥𝑖:1 + 𝑓 𝑥𝑖 𝑓 ′′′ 𝑥𝑖 3
𝑓 ′′ 𝑥𝑖 = − ℎ −···
ℎ2 ℎ2
𝑓 𝑥𝑖:2 − 2𝑓 𝑥𝑖:1 + 𝑓 𝑥𝑖
𝑓 ′′ 𝑥𝑖 = +𝑂 ℎ
ℎ2
 This is the second forward finite divided difference.
NUMERICAL DIFFERENTIATION
BACKWARD DIFFERENCE APPROXIMATION OF HIGHER DERIVATIVE:
 Using similar manipulation we get the second backward finite divided difference :

𝑓 𝑥𝑖 − 2𝑓 𝑥𝑖;1 + 𝑓 𝑥𝑖;2
𝑓 ′′ 𝑥𝑖 = +𝑂 ℎ
ℎ2

CENTERED DIFFERENCE APPROXIMATION OF HIGHER DERIVATIVE:


 Using similar manipulation we get the second centered finite divided difference :

𝑓 𝑥𝑖:1 − 2𝑓 𝑥𝑖 + 𝑓 𝑥𝑖;1
𝑓 ′′ 𝑥𝑖 = + 𝑂 ℎ 2
ℎ2
REFERENCE
Chapra, S. C., & Canale, R. P. (2010). Numerical Methods for
Engineers (6th Edition). McGraw-Hill.
THE END

You might also like