Professional Documents
Culture Documents
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1
4.0 Introduction
3
• Lets build the Taylor series term by term. For
example the first term in the series is
f(xi+1) ≈ f(xi) (4.2) zero order approximation, only
true if xi+1 and xi are very close to
each other.
• If the function changes at all over the interval,
additional term needed to provide a better estimate.
4
• To capture some of the curvature that the function
might exhibit, a second-order term is added:
f
f ( xi 1 ) f ( xi ) f ( xi )( xi 1 xi ) ( xi 1 xi ) 2 (4.4)
2!
The sign becomes “=” since the equation considers for all terms
5
Taylor Series can also be generalized as
f 2 f (3) 3 f ( n) n
f ( xi 1 ) f ( xi ) f ( xi )h h h h Rn (4.7)
2! 3! n!
7
Solution 4.1 Because we are dealing with a known function, we can compute values for 𝑓(𝑥)
between 0 and 1. The results (Fig. 4.1) indicate that the function starts at 𝑓 0 =
1.2 and then curves downward to 𝑓 1 = 0.2. Thus, the true value that we are
trying to predict is 0.2.
at 𝑥 = 1.
f(xi+1) ≈ f(xi) + f′(xi) (xi+1-xi) 𝑓 ′ (0) = −0.4 0.0 3 − 0.45 0.0 2 − 1.0 0.0 − 0.25 = −0.25
Therefore, the first-order approximation is [Eq. (4.3)]
Additional terms would improve the approximation even more. In fact, the
inclusion of the third and the fourth derivatives result in exactly the same equation
we started with:
9
Figure 4.1 The approximation of at x = 1
10
• The nth order Taylor series expansion will be exact for
an nth order polynomial.
13
Solution 4.2
The zero-order approximation is [Eq.(4.3)]
𝜋 𝜋
𝑓 ≅ cos = 0.707106781 ( f(xi+1) ≈ f(xi))
3 4
For the first-order approximation, we add the first derivative term where
For the second-order approximation, we add the second derivative term where
𝑓"(𝑥) = − cos 𝑥:
𝜋 𝜋 𝜋 𝜋 cos 𝜋/4 𝜋 2
𝑓 ≅ cos − sin − = 0.497754491
3 4 4 12 2 12
with 𝜀𝑡 = 0.449 percent. Thus, the inclusion of additional terms results in an
improved estimate.
14
Solution 4.2
The process can be continued and the results listed, as in Table 4.1.
TABLE 4.1 Taylor series approximation of f(x) = cos x at xi+1 =π/3 using a base point
of π/4. Values are shown for various orders (n) of approximation.
15
4.1.1 The Remainder for the Taylor Series Expansion
• To demonstrate how Taylor series is used to estimate
numerical error, we must understand why is included in Eq.
(4.8).
• Suppose we truncated the Taylor series expansion after the
zero order term, to yield f(xi+1) ≈ f(xi)
• Graphical depiction of zero order is shown in Fig. 4.2
R0 f ( xi )h
17
R0
f ' ( )
h
f " ( ) 2
First order : R1 h (4.11)
2!
First-order Truncation
approximation error 19
• The first part is the same as in Eq. (1.11).
• Second part is the truncation error associated with
approximation of the derivative.
• Using Eq. (4.6) & (4.14) yields
R1 v' ' ( ) R1
(ti 1 ti ) (4.15) or O(ti 1 ti ) (4.16)
ti 1 ti 2! ti 1 ti
20
Example 4.3 The effect of nonlinearity and step size on the Taylor
Series Approximation
Problem statement. Figure 4.4 is a plot
of the function f(x)=xm , m = 1,2,3,4
over the range from x = 1 to 2.
21
Solution 4.3
Equation (E4.3.1) can be approximated by a first-order Taylor series expansion, as
in
𝑓 2 =1+1 1 =2
and
𝑅1 = 0
The remainder is zero because the second and higher derivates of a linear function
are zero. Thus, as expected, the first-order Taylor series expansion is perfect when
the under lying function is linear.
22
Solution 4.3
For m = 2, the actual value is f(2) =22 =4. The first-order Taylor series
approximation is
f(2) = 1+2(1)=3
and
2
𝑅1 = (1)2 + 0 + 0 + ⋯ = 1
2
For m = 3, the actual value is f(2) =23 =8. The Taylor series approximation is
and
6 6
𝑅1 = (1)2 + (1)3 + 0 + 0 + ⋯ = 4
2 6
Again, there is a discrepancy that can be determined exactly from the Taylor series.
23
Solution 4.3
For m = 4, the actual value is f(2) = 24 =16. The Taylor series approximation is
and
12 24 24
𝑅1 = (1)2 + (1)3 + (1)4 + 0 + 0 + ⋯ = 11
2 6 24
On the basis of these four cases, we observe that Ri increases as the function
becomes more nonlinear. Ri accounts exactly for the discrepancy. This is because
Eq. (E4.3.1) is a simple monomial with finite number of derivatives. This permits a
complete determination of the Taylor series remainder.
Next, we will examine Eq. (E4.3.2) for the case m = 4 and observe how Ri changes
as the step size h is varied. For m = 4, Eq. (E4.3.2) is
𝑓 1 + ℎ = 1 + 4ℎ
With a remainder of
𝑅1 = 6ℎ2 + 4ℎ3 + ℎ4
24
Solution 4.3
TABLE 4.2 Comparison of the exact value of the function f(x)=x4 with the first-
order Taylor series approximation. Both the function and the
approximation are evaluated at x+h, where x= 1
First-Order
h True R1
Approximation
1 16 5 11
0.5 5.0625 3 2.0625
0.25 2.441406 2 0.441406
0.125 1.601807 1.5 0.101807
0.0625 1.274429 1.25 0.024429
0.03125 1.130982 1.125 0.005982
0.015625 1.063980 1.0625 0.001480
25
From the example 4.3, the following observation can be drawn:
• As h reduces, the discrepancy between true value and approximation
reduces as well.
• At a small value of h, the error becomes proportional to h2 as shown in Fig.
4.5 & Table 4.2.
Figure 4.5
Log-log plot of the Remainder R1 of the first-
order Taylor series approximation of the
function f(x)=x4 versus step size h. A line with a
slope of 2 is also shown to indicate that as h
decreases, the error becomes proportional to h2.
26
• The error of the first order Taylor series approximation
decreases as m approaches 1 and as h decreases.
• Taylor series becomes more accurate when the function we
are approximating becomes more like a straight line over the
interval of interest
• Two possible way can be done that are by reducing the size of
interval or straightening the function by reducing m.
• However, only the first option is possible since the latter
option depends on the problem and not all system can be
modeled as a linear function.
27
Week 4 Exercise 1
x3 x5 x7
sin x x
3! 5! 7!
Starting with the simplest version, sin x = 1, add terms one at
a time to estimate sin ( / 3). After each new term is added,
compute the true and approximate percent relative errors.
Use your pocket calculator to determine the true value
(considered 6 decimal point of true value). Add terms until
the absolute value of the approximate error estimate falls
below an error criterion confirming to two significant figures.
28
Week 4 Exercise 2
f ( x) 25 x 3 6 x 2 7 x 88
29
4.1.3 Numerical Differentiation
• Derivative can be approximate numerically using Taylor Series, this is called
Finite divided difference.
f ( xi 1 ) f ( xi )
f '( xi ) O ( xi 1 xi ) (4.17)
xi 1 xi
or
f i
f '( xi ) O (h) (4.18)
h
fi first forward difference
h step size Recall the Taylor series:
f ( xi )
f ( xi 1 ) f ( xi ) f ( xi )( xi 1 xi ) ( xi 1 xi ) 2
fi / h first finite divided difference 2!
• Forward divided difference is one of the many that can be developed from
the Taylor series to approximate derivatives numerically
• More accurate approximation of the first derivative can be developed by
including higher-order terms
30
Backward Difference Approximation of the
First derivative
• Taylor series can be expended backward to calculate a previous value
on the basis of a present value, as in:
f " ( xi ) 2
f ( xi 1 ) f ( xi ) f ' ( xi )h h (4.19)
2!
• Truncating this equation after the first derivative and rearrange yields:
f ( xi ) f ( xi 1 ) f1
f ' ( xi ) O ( h) (4.20)
h h
O(h) is the error
f1 is first backward difference Recall the Taylor series:
f
f ( xi 1 ) f ( xi ) f ( xi )( xi 1 xi ) ( xi 1 xi ) 2
2!
31
Centered Difference Approximation of the First Derivative
Centered difference:
• Truncation error is of the order h2
• Thus, centered difference approximation is more accurate
32
Figure 4.6 Graphical depiction of (a) forward (b) backward and (c) centered
finite-divided-difference approximations of the first derivative
33
Example 4.4: Finite-Divided-Difference Approximations of
Derivatives
Problem Statement. Use forward and backward difference approximations of O(h) and a centered
difference approximation of O(h2) to estimate the first derivative of
at x = 0.5 using a step size h = 0.5. Repeat the computation using h = 0.25. Note that the derivative can
be calculated direcly as
These values can be used to compute the forward divided difference [Eq. (4.17)],
0.2−0.925
f’(0.5) ≅ = -1.45 𝜀𝑡 = 58.9%
0.5
34
The backward divided difference [Eq. (4.20)],
f ( xi ) f ( xi 1 )
f’(0.5)≅
0.925−1.2
= -0.55 𝜀𝑡 = 39.7%
f ' ( xi )
0.5 h
and the centered divided difference [Eq. (4.22)],
f ( xi 1 ) f ( xi 1 )
f’(0.5)≅
0.2−1.2
= -1.0 𝜀𝑡 = 9.6 %
f ' ( xi )
1.0 2h
for h = 0.25,
0.63632813 −0.925
f’(0.5)≅ = -1.155 𝜀𝑡 = 26.5%
0.25
0.925−1.10351563
f’(0.5)≅ = -0.714 𝜀𝑡 = 21.7% Observations:
0.25
-Centered difference more accurate
and the centered divided difference, -Halving the step size approximately
halves the errors of the backward and
0.63632813 −1.10351563 forward and quarters the centered
f’(0.5)≅ = -0.934 𝜀𝑡 = 2.4%
0.5
35
Finite Difference Approximations of Higher Derivatives
Finite Difference Approximation of Higher Derivatives. Besides first derivatives, the Taylor series
expansion can be used to derive numerical estimates of higher derivatives. To do this, we write a
forward Taylor series expansion for f(xi+2) in terms of f(xi):
𝑓 ′′ (𝑥 𝑖 )
f (xi + 2) = f(xi) + f ’(xi)(2h) + 2ℎ2 + . . . (4.23)
2!
4.21
Equation (4.2.1) can be multiplied by 2 and subtracted from Eq. (4.23) to give
36
This relationship is called the second forward finite divided difference. Similar manipulations can be
employed to derive a backward version
𝑓 𝑥 𝑖 − 2𝑓 𝑥 𝑖−1 + 𝑓 𝑥 𝑖−2
f ’’(xi) = +O ℎ
ℎ2
𝑓 𝑥 𝑖+1 − 2𝑓 𝑥 𝑖 + 𝑓 𝑥 𝑖−1
f ’’(xi) = + O ℎ2
ℎ2
As was the case with the first-derivative approximations, the centered case is more accurate. Notice also
that the centered version can be alternatively expressed as
𝑓 𝑥 𝑖+1 −𝑓 𝑥 𝑖 𝑓 𝑥 𝑖 −𝑓 𝑥 𝑖−1
−
ℎ ℎ
f ’’(xi)≅
ℎ
37
4.2 Error Propagation
To study how errors in number can propagate through mathematical functions.
Example: what is estimation error if we multiple two numbers that has an error ?
38
Figure 4.7 Graphical depiction of first –order error propagation
39
Example 4.5
f(2.5) = 15.625±0.1875
or that the true value lies between 15.4375 and 15.8125. In fact, if x were actually
2.49, the function could be evaluated as 15.4382, and if x were 2.51, it would be
15.8132. For this case, the first-order error analysis provides a fairly close estimate
of the true error.
40
4.2.2 Function of more than one Variable
For a function of two independent variable u and v, Taylor series can be
written as:
𝜕𝑓 𝜕𝑓
𝑓 𝑢𝑖+1 𝑣𝑖+1 = 𝑓 𝑢𝑖 , 𝑣𝑖 + 𝑣𝑖+1 − 𝑢𝑖 + 𝑣𝑖+1 − 𝑣𝑖
𝜕𝑢 𝜕𝑣
Where all partial derivatives are evaluated at the base point i. If all second order
and higher terms are dropped, (4.26) can be solved for
f ∆𝑥~ +
∆𝑓 f ∆𝑥~ + ⋯ +
𝜕𝑓 f ∆𝑥
𝜕𝑓 (4.27)
f ( ~
∆𝑓(𝑥 x11,,𝑥~ ,...,. , 𝑥~
x22, … x𝑛n )≅ 𝜕𝑥 x11 x22 ... ~
xn𝑛
x1
1 𝜕x2
2
𝜕𝑥
xn
𝑛
41
Example 4.6
𝐹𝐿4
𝑦=
8𝐸𝐼
Where F = a uniform side loading (lb/ft), L = height (ft), E = the modulus of
elasticity (lb/ft2), and I = the moment of inertia (ft4). Estimate the error in y given
the following data:
𝐹 = 50lb/ft ∆𝐹 = 2lb/ft
𝐿 = 30 ft ∆𝐿 = 0.1 ft
42
Solution. Employing Eq. (4.27) gives
𝜕𝑦 𝜕𝑦 𝜕𝑦 𝜕𝑦
∆𝑦 𝐹 , 𝐿, 𝐸 , 𝐼 = ∆𝐹 + ∆𝐿 + ∆𝐸 + ∆𝐼
𝜕𝐹 𝜕𝐿 𝜕𝐸 𝜕𝐼
Or
𝐿4 𝐹 𝐿3 𝐹 𝐿4 𝐹 𝐿4
∆𝑦 𝐹 , 𝐿, 𝐸 , 𝐼 = ∆𝐹 + ∆𝐿 + ∆𝐸 + ∆𝐼
8𝐸 𝐼 2𝐸 𝐼 8𝐸 2 𝐼 8𝐸 𝐼 2
Therefore, y = 0.5625 ± 0.039375. In the other word, y is between 0.523125 and 0.601875 ft.
The validity of these estimates can be verified by substituting the extreme values for variables
into the equation to generate an exact minimum of
48(29.9)4
𝑦𝑚𝑖𝑛 = = 0.52407
8 1.51𝑥108 0.0606
And
52(30.1)4
𝑦𝑚𝑎𝑥 = = 0.60285
8 1.49𝑥108 0.0594
Thus, the first-order estimates are reasonably close to the exact values.
43
TABLE 4.3 Estimated error bounds associated with common mathematical
operations using inexact numbers .
Addition
Subtraction
Multiplication
Division
44
4.2.3 Stability and Condition
The condition of a mathematical problem relates to its sensitivity to changes in its
input values. We say that a computation is numerically unstable if the uncertainty
of the input values is grossly magnified by the numerical method.
For this case, the major cause of ill conditioning appears to be derivative. This makes
sense because in the vicinity of , the tangent approaches both positive and negative
infinity.
46
4.3 Total Numerical Error
• Total numerical error = truncation error + round-off error
• Round-off error will increase due to subtractive
cancellation or due to increase in the number of
computation.
• To minimize round-off error is by increasing the
significant figure of computer.
• To reduce truncation error is by reducing the step size.
• However, by decreasing the step size, the round-off error
increases due to the subtractive cancellation and
increase in computation.
• The strategy is to find appropriate step size as shown in
Figure 4.8
47
Figure 4.8 A graphical depiction of the trade-off between round-off
and truncation error that sometimes comes into play in the course
of a numerical method. The point of diminishing returns is shown
where round-off error begins to negate the benefits of step-size
reduction.
48
Try to solve this problems
49