c1 - Intro and Error Analysis
c1 - Intro and Error Analysis
Outcomes:
Scope and Preview: In this part, we will investigate how numerical methods are used to
approximate the true solution of a problem. An analytical method provides an exact solution.
The reliability of the numerical method will be analyzed by performing an error analysis. Taylor
series expansion (TSE) of a function in one variable will be discussed in details. This is
particularly important since TSE is used as a basis of approximation in the numerical analysis.
1.2 Error Analysis. Error analysis is very important especially when numerical methods are
implemented on computers. We will study sources of error in numerical methods and how the
error is quantified.
1.3 Approximation of a function. TSE will be used to approximate the value of the
function at any point of interest. The error associated with this approximation will be defined.
Application in numerical differentiation of a function will be introduced.
1
1.0
Numerical Methods
with Applications
INTRODUCTION
In engineering and sciences, we rarely come across simple and straight forward situations which
can be solved analytically. Often the problems are complex that analytical solutions are either
extremely difficult or impossible to obtain. Furthermore when the constraints are imposed on the
problem, the complexity also increases. Therefore, numerical methods provide an alternative
means of approximating the true solution via computer implementation. They are sometimes
referred to as numerical analysis. Note, however, the numerical solution by no means should
replace the analytical solution if it can be easily and practically obtained. The analytical method
provides continuous solution of the problem while the numerical method only gives solution at
discrete points.
Numerical computations combine two important tools in engineering problem solving: 1)
Mathematics, and 2) computers. They influence the practices of engineering design and modeling
process in the present world. Therefore, in order to be competence in solving engineering
problems, a person must enhance his or her knowledge and skills of these tools.
1.1
1.1.1
qo f (qi , c, u)
where
q0
qi
c
u
= dependent variable
= independent variable(s)
= parameter(s)
= forcing function(s)
(1-1)
Numerical Methods
with Applications
F ma
(1-2)
and for one-dimensional problem (as in this case), we can write eq(1-2) as
or
dv
F
dt
(1-3)
d 2x
F
dt 2
(1-4)
We see that eq.(1-4) relates a linear position x (dependent variable) to the applied force F
(forcing function) and the time t (independent variable). This relation forms a mathematical
model of a body being acted upon by a force in one dimension. The mass m is the only parameter
in the above model. The complexity of the model increases if we decide to include the effect of
friction and other considerations such as wind resistance.
Once the model is obtained, numerical method is employed in predicting and obtaining the
information about the performance or behaviors of the model. Remember that the method only
provides approximate information of the model.
1.1.2
Consider a free falling object when it is released from rest at time t = 0 s. Neglecting the air
resistance, the equation of motion is given by
y y0 v0t 21 gt 2
where
(1-5)
dy
v v0 gt
dt
(1-6)
v = 0 + 9.81t
= 9.81t
We can solve for the velocity at any time t, for example, at t = 2.0 s,
v=
Numerical solution may be expressed using one of the standard formulas, such as forward finite
difference as follows.
Numerical Methods
with Applications
vi
yi 1 yi
ti 1 ti
(1-7)
In order to use this formula, we need to have the values of the position y at the discrete time t (at
least at two different points with one being at ti and the other at ti+1). For example, the position y
may be tabulated at time t as shown below
t (s)
y (m)
0
0
2
19.62
3
44.145
vi
44.145 19.62
= 12.2625 m/s
3 2
2
19.62
2.5
30.65625
v (t = 2) = 22.0725 m/s
t (s)
y (m)
2
19.62
2.1
21.63105
v (t = 2) = 20.1105 m/s
t (s)
y (m)
2
19.62
2.05
20.61326
v (t = 2) = 19.86525 m/s
We observe that the numerical solution approaches the true value when the step size is reduced.
However, there is a limit to how small could the step size be. This is especially important when a
computer is used in the solution procedures.
Numerical Methods
with Applications
perspectives.
4. Reduce the amount of time used in arithmetic operations.
However, we need to understand the limitations and pitfalls of each numerical methods before we
can effectively and efficiently employ them to solve problems with acceptable accuracy. There
are several factors that influence a decision-making process in choosing one particular method
over the others.
1. complexity of the problem
2. societal importance of the problem
3. solutions are unbiased and precise
4. cost effective
5. minimal environmental impacts.
In general, engineering problem solving and analysis can be represented as shown in the diagram
below.
Problem
definition
Theory
Mathematical
model
Experimentation
Performance verification:
analytical/numerical methods,
statistics, computers, graphics, etc.
Implementation
Numerical Methods
with Applications
110
120
metal sheet
The length of the metal sheet is read as 116.5 units (4 s.ds) which contains one estimated digits.
If we were to read the length as 116.57 units, then the last digit which is 7 is not significant.
Suppose the electric meter indicates the electric power consumption as shown,
3
4
watts
The reading to the nearest watt is recorded as 52970.35 watts (7 s.ds). It would be incorrect to
read the meter as 52970.348 watts which now has two doubtful digits. The following table
illustrate more about the number of significant digits contain in the numbers.
Number
2.347
1.652 0
189.708
0.001 2
0.001 200
Significant Digits
4
5
6
2
4
The reasonable number of significant digits in calculations should be determined from the
relative error required in the final answer. *Rule does not apply to conversion factors and exact
numbers.
Numerical Methods
with Applications
(ii) Accuracy and Precision. Precision in numerical method is referred to the consistency of the
estimates to be closed to each other. On the other hand, accuracy is the measure of closeness of
the estimate to the target.
Increasing Accuracy
(a)
(b)
(c)
(d)
Increasing Precision
C
C
C
C
Programming result,
input
0.1234567890123
output :
0.1234567910433
7
Numerical Methods
with Applications
0.1234567890123
output :
Remark:
0.12346 (5 d.ps)
1. If any solution is sought with too much precision, REr will be dominant.
Otherwise, lack of mathematical accuracy (TEr) prevails.
2. REr and TEr constitute a limit to how accurately a solution can be obtained by
implementing numerical methods on computers.
Recall the approximation of the velocity v (which is essentially the first derivative of the
function y ), we may express the general form of the first derivative for any function f(x) at the
base point x0 using first finite forward difference formula as
mapprox f ' ( x0 )
f ( x0 h ) f ( x0 )
h
(1-8)
and the true value (analytical solution) is represented by a slope of the tangent line at x0 which
may be shown in the figure below,
mapprox
mtrue
f(x)
x0
x0 + h
Numerical Methods
with Applications
shows TEr.
when h is too small, REr dominates. This observation suggests that there must be an optimum
value of h .
Summary:
(iii) Error Quantification. When the true value of the quantity is known, the error is quantified
in two different but related ways.
Let x denote an exact (or true) value and x* denote an approximate (or estimated) value or
simply an approximation. We may then express the relation,
or
(1-9a)
(1-9b)
which defines the error as the difference between the true value and the approximation.
(True) Absolute error:
(1-10)
Et x x *
Note that the absolute error does not reflect the degree of its influence.
For example,
do not suggest the significant or scale of the error, though, both have same the value of the
absolute error. In view of this limitation, the second way of quantifying the error is introduced.
Numerical Methods
with Applications
x x*
(1-11a)
Note that the absolute error is normalized or scaled with respect to (or relative to) the true value
so that the influence of the error can be significantly interpreted. Usually the relative error is
expressed in terms of percentage, that is
x x*
x
x100%
(1-11b)
(iv) Error bound and Its Propagation. Any number (x*) satisfying the inequality
( x*) x x *
(1-12)
is called an error bound or an absolute error bound for the error of x* as an approximation of
x.
Remark: all numbers larger than (x*) also serve as error bounds.
Similarly, Any number (x*) satisfying the inequality
( x*)
x x*
(1-13)
( x*)
x
(1-14)
( x*)
x*
(1-15)
10
Numerical Methods
with Applications
(1-16)
Truncating after the first derivative term and rearranging the remaining terms to give
(1-17a)
(1-17b)
where
f f
f
,
,...,
x1 x 2
x n
f
f
f
x1 *
x2 * ...
xn *
x1
x2
xn
(1-18)
and xn*.
11
Numerical Methods
with Applications
Condition number (Nc ): It provides a measure of the extent to which a change in x affects a
change in f(x). A function is said to be ill-conditioned if a small change (i.e. perturbation) in x
causes a large change in f(x). Nc is the ratio of the relative error of f(x) and x
x * f ' ( x*)
Nc
f ( x*)
1
1
f ( x)
( x)
and
f ( x*)
f ( x*)
(1-20)
x x*
x*
(1-21)
Solution:
or
12
Numerical Methods
with Applications
For a beam with one end fixed and the other end free (as shown below), the
deflection of the beam y is given by
F
FL4
8 EI
L
y
F* = 120 lbf/ft
L* = 27 ft
E* = 1.65(108) lbf/ft2
I* = 0.072 ft4
F* = 5 lbf/ft
L* = 0.1 ft
E* = 8.0(105) lbf/ft2
I* = 0.0005 ft4
The deflection y is
y*
(120)(27) 4
8(1.65x108 )(0.072)
= 0.6710 ft (4 d.ps)
y
y
y
y
F *
L *
E * I *
F
L
E
I
L4
FL3
FL4
FL4
F *
L *
E *
I *
2
8 EI
2 EI
8E I
8 EI 2
13
Numerical Methods
with Applications
(v) Error Quantification in Numerical Methods: In the absent of the true value (which is
usually the case in numerical methods), the following error calculation is employed.
Let
xnew denote
xold denote
(1-22a)
(1-22b)
(1-23a)
x new
x new
x100%
(1-23b)
In employing the numerical methods, particularly the iterative approaches, we are basically
interested in whether the absolute value of the approximate percent relative error a is less than
the prespecified tolerance s (or desired accuracy) that is
a s
(1-24)
(1-25a)
E s (0.5x10 p )
(1-25b)
1 d.p accuracy
2 d.ps accuracy
a s
a s
= 0.5x101 = 5%
= 0.5x100 = 0.5%
14
Numerical Methods
with Applications
p=3
a s
3 d.ps accuracy
= 0.5x10-1 = 0.05%
Note: It is the user who determines the desired accuracy or the acceptable error. This usually
depends on the importance of the problem and its intended ends.
Error estimates of series approximation.
Example 1-3:
...
2! 3!
n!
Approximate the function at x = 0.5 with an accuracy to 3 d.ps and also calculate the true
percent relative error.
Solution:
True value,
#
Equivalent expression and value
Terms
1
ex 1
2
e x 1 x = 1 + 0.5 = 1.5
ex 1 x
4
5
6
x2
2!
x2
ex 1 x
2!
x2
ex 1 x
2!
x2
ex 1 x
2!
y
t %
1.64..1 100% 39.3
1.64..
1.64. .15
. 100% 9.02
1.64. .
1.64. .1.625 100% 1.44
1.64. .
= 1.5 + 0.52/2
x3
3!
x 3 x4
3! 4!
x 3 x 4 x5
3! 4! 5!
a %
15
. 1 100%
15
.
0.175
1.27
0.0172
0.158
0.00142
0.0158
ex
3 terms
2 terms
1.0
1 terms
x
1
15
33.3
Numerical Methods
with Applications
Worksheet 1.3:
sin( x) x
x 3 x5
x 2 n 1
. . . ( 1) n
3! 5!
(2n 1)!
n = 0,1,2,3,...
Solution:
True value,
sin(/2) = 1.0
For p = 4,
s (0.5x102 4 )% 0.005%
sin(/2) 1.570796
a = 57.1%
a = 7.52%
a = 0.453%
a = 0.0157%
a = 0.00003%
16
Numerical Methods
with Applications
f ' ( x0 )
f ' ' ( x0 )
f ( n ) ( x0 )
( x x0 )
( x x0 ) 2 ...
( x x0 ) n Rn
1!
2!
n!
(1-26)
x x0 h
Defining
or
h x x0 step size,
f ' ( x0 )
f ' ' ( x0 ) 2
f ( n ) ( x0 ) n
f ( x ) f ( x0 )
h
h ...
h Rn
1!
2!
n!
where
(1-27)
Rn
(x )
f
n!
x0
( n 1)
( ) d
(1-28)
where is a dummy variable. Note that Maclaurin series is a special form of Taylor series for
which x0 = 0.
2
17
Numerical Methods
with Applications
f ( x)
k 0
f ( k ) ( x0 ) k
h Rn
k!
(1-29)
Note that 0! = 1.
From the second theorem of mean for integrals, eq.(1-28) yields
Rn
f ( n 1) ( ) n 1
h
(n 1)!
where
x0 x
(1-30)
which is called the derivative or the Lagrange3 form of the remainder with being an unknown
value. Other formulas for Rn are also available. They are available in most advanced calculus
text.
f ( x ) f ( x0 )
first-order
f ( x ) f ( x0 )
f '( x0 )
h
1!
(1-32)
second-order :
f ( x ) f ( x0 )
f '( x0 )
f ' ' ( x0 ) 2
h
h
1!
2!
(1-33)
nth-order
f '( x0 )
f '' (x0 ) 2
f ( n ) ( x0 ) n
f ( x ) f ( x0 )
h
h ...
h
1!
2!
n!
(1-31)
(1-34)
18
Numerical Methods
with Applications
Example 1-4: Use zero- through third-order TSE to approximate the function
f ( x) 0.5x3 01
. x2 0.8x 0.7
at x = 1.0 and the base point (a) x0 = 0 and (b) x0 = 0.8. Also calculate both the true and
approximate percent relative errors for each order.
Solution:
True value,
order
0th
1st
2nd
3rd
f (1) 05
. (1)3 01
. (1) 2 08
. (1) 0.7 = 0.5
f(x) = 0.5x3 -0.1x2 +0.8x - 0.7 f(0) = -0.7
f(x) = 1.5x2 -0.2x +0.8
f(0) = 0.8
f(x) = 3.0x -0.2
f(0) = -0.2
f(x) = 3.0
f(0) = 3.0
(4)
f (x) = 0.0
t %
0.5 ( 0.7 )
100% 240
0.5
0.5 ( 01
.)
100% 80
0.5
a
01
. (0.7 )
100% 800
01
.
100
100
We observe that though, the true percent relative error is zero, the approximate percent relative
error is 100%. In practice, when using numerical method (in the absent of the true value), we
will continue with higher order approximation(s) that is
4th-order approximation:
f (1) 0.5
( 0)
(10
. ) 3 0.5
4!
19
and a = 0%.
Numerical Methods
with Applications
0th
1st
f (1) 0132
.
2nd
3rd
(16
. )
( 0.2 ) 0.452
1!
( 2.2 )
f (1) 0.452
( 0.2 ) 2 0.496
2!
(3.0)
f (1) 0.496
( 0.2 ) 3 05
.
3!
t %
a %
73.6
9.6
70.8
0.8
8.9
0.8
In practice, we usually require the result to be within a specified tolerance. For example, we may
want the result to be accurate at least to 3 d.ps. If this is the case, then we will have to continue
with higher order approximation(s).
p = 3,
s = 0.05%
4th-order approximation:
f (1) 0.5
( 0)
(10
. ) 3 0.5
4!
20
and a = 0%.
Numerical Methods
with Applications
Worksheet 1-4:
f ( x ) x 4 0.7 x 3 2 x 2 x 62.5
at x = 5.0 and the base point x0 = 4.5 with an accuracy to 3 d.ps. Also calculate the true percent
relative error for each of the orders.
Solution:
True value,
t %
43.1
( 302.975)
( 0.5)
1!
7.08
38.8
(2201
.)
( 0.5) 2
2!
0.530
6.59
(1038
. )
(0.5)3
3!
0.0149
0.515
( 24)
( 0.5) 4
4!
0.0
0.0149
0th
1st
f (5) 238.775
= 390.2625
2nd
f (5) 390.2625
= 417.775
3rd
f (5) 417.775
= 419.9375
4th
f (5) 419.9375
= 420
21
Remark:
Numerical Methods
with Applications
1. The function and its n+1 derivatives are assumed to be continuous in the
interval of interest [x0, x].
2. Order of approximation is the highest order of the derivatives.
3. Accuracy of approximation improves as order of TSE increases or when the
step size h decreases.
4. Higher order terms become apparent when the nonlinearities of the function
increases or when the step size increases.
5. When the function is linear (i.e. a polynomial), the first-order TSE with
reasonably small step size is usually adequate.
6. TSE is used when the function is not known or in order to obtain approximate
solutions for trigonometric and logarithmic functions.
In practice, we may use the known function to illustrate the practicality of the TSE.
(iii) Remainder, Rn
Recall the derivative form of the remainder, eq.(1-30),
Rn
f ( n 1) ( ) n 1
h
( n 1)!
22
Numerical Methods
with Applications
Rn ( h n 1 )
(1-35)
which implies that the truncation error is of the order of hn+1. In other words, it is proportional
to the step size h raised to the power of (n+1). It enables us to judge the comparative error of
numerical methods based on TSE.
For example,
when
In general, we assume that the truncation error is decreased with addition of more
terms in the TSE and with smaller step size h.
We may also gain some other insights about the remainder. Lets define an upper bound on the
magnitude of the reminder Rn such that
Rn Rn ,u
(1-36)
with
Rn ,u
where
M
h n 1
( n 1)!
and
f ( n 1) () M
(1-37,38)
Example 1-5:
Recall the exponential function using the Maclaurin series example 1-3,
ex 1
x2 x3
xn
...
2! 3!
n!
Define an upper bound of the remainder and determine the number of terms n so that the
approximation about x = 1.0 is accurate to 1 d.p.
23
Solution:
Note
Numerical Methods
with Applications
x0 = 0.
The remainder
Rn
f ( n 1) () n 1
e
h
x n 1
( n 1)!
( n 1)!
f (1) e1 1 1
1 1
1
e
...
2! 3!
n! ( n 1)!
Defining,
Rn
e
e
( n 1)! ( n 1)!
Rn
e
e
Rn,u
(n 1)!
(n 1)!
Rn
3
(0.5x10 p )
( n 1)!
24
(E1.5-1)
Numerical Methods
with Applications
Example 1.6:
f ( x)
1
x
at x = 2.0 with x0 = 1.0. Evaluate the true percent relative error for all cases.
Solution:
Derivatives,
True value,
1 3
f '( x ) x 2
2
3 5 2
f ''( x ) x
4
15 7
f '''( x ) x 2
8
105 9 2
(4 )
f ( x)
x
16
945 112
f ( 5) ( x )
x
32
f(2.0)
1st:
41.4
1.0
29.3
2nd:
t %
23.7
25
20.5
Numerical Methods
with Applications
18.22
16.58
15.32, 14.30,
13.47
Note: Although (in this example), the addition of more terms will further reduce the error, but
there is no significant improvement. It suggests that an infinite number of terms is required in
order to get the approximation closed enough to the true value.
This is true for most of the function with
(1) an infinite number of the derivatives and
(2) relatively large step size.
In addition, for some functions, the solution may indeed diverge. This depends on the interval of
validity of x for that function.
26
Numerical Methods
with Applications
Worksheet 1.5:
Solution:
Now
True value,
h = x - x0 = 2.0 - 1.5 = 0.5 (which is half of step size in the previous example)
=>
f(1.5) = 0.8165,
f(1.5) = - 0.4536,
f(1.5) = - 0.2722,
f (4)(1.5) = 1.0584,
f(1.5) = 0.2722
f(5)(1.5) = - 3.1753
Order of approximations
t %
15.47
3.77
1.032
0.2.97
0.0849
0.0283
0.00745
0.00399
0.70715, 0.70707
Note: the approximate value approaches the true value faster when the step size is reduced. After
the fifth-order approximation, the result is accurate at least up to 3 d.ps.
27
Numerical Methods
with Applications
xi = x0
xi+1 = x
Ro
(1-39)
f '( xi )
f ''( xi ) 2
h
h . . . Rn
1!
2!
(1-40)
Ro f '( xi )h
(1-41)
f(xi+1)
f(x)
f(x)
f(x)
f(x)
f()
Exact
R0
slope = R0/h
f(xi)
0th-order
xi+1
xi
xi
(a)
xi+1
(b)
Figure 1.8: Graphical depiction of error in TSE
Using derivative mean-value theorem: if a function f(x) and its first derivative are continuous
over an interval from xi and xi+1, then there exists at least one point on the function that has a
slope, designated by f(), that is parallel to the line joining f(xi ) and f(xi+1 ).
28
Numerical Methods
with Applications
Thus, the slope f() is equal to the rise Ro divided by the run h, or
f '( )
Ro
h
=>
Ro f '( ) h
(1-42)
R1
f ''( ) 2
h
2!
(1-43)
R2
f '''( ) 3
h
3!
(1-44)
f ( xi 1 ) f ( xi ) f '( xi )( xi 1 xi ) R1
(1-45)
f '( xi )
f ( xi 1 ) f ( xi )
R1
xi 1 xi
xi 1 xi
st
Truncation
1 order
error
(1-46)
approximation
From eq.(1-43) and eq.(1-46), we can then estimate the truncation error associated with the
approximation of the first derivative using TSE as
R1
f ''( )
h
h
2!
or
R1
( h)
h
where
h = xi+1 - xi
(1-47)
We conclude that the estimate of the first derivative using TSE has a truncation error of order of
h i.e. the error of the first derivative approximation is proportional to the step size. It follows
that the error will be halved if the step size is halved.
29
Numerical Methods
with Applications
(1-48)
Rearranging terms to give the finite difference formula for the first derivative as
f ' ( xi )
where
f ( xi 1 ) f ( xi )
(h)
h
or
f '( xi )
f i
(h)
h
(1-49)
h step size
f (xi 1 ) f ( xi ) f ' ( xi )h
Truncating all terms after the first derivative term and rearranging the equation yields
f ' ( xi )
where
f ( xi ) f ( xi 1 )
( h )
h
or
30
f ' ( xi )
f i
( h )
h
(1-51)
Numerical Methods
with Applications
f ( xi 1 ) f ( xi 1 ) 2 f ' ( xi ) h
(1-52)
Again solving for the first derivative and rearranging the terms to give
f '( xi )
h
2h
6
f ' ( xi )
or
f ( xi 1 ) f ( xi 1 )
( h2 )
2h
(1-53)
Notice that the error for the central different method is of the order of h2 as compared to h for
the forward and backward difference methods. Therefore, central difference method gives better
approximation of the derivative than the other two methods.
The three methods can be depicted graphically as shown in figure 1.9 below.
f(xi+1)
f(xi+1)
f(xi)
f(xi)
f(xi )
exact
exact
exact
f(xi-1 )
f(xi-1)
xi
(a) FDM
xi+1
xi-1
xi
(b) BDM
xi-1
xi
xi+1
(c) CDM
We will study numerical differentiation in more details in part Five. This includes the higher
accuracy formulas and also higher order derivatives.
31
Numerical Methods
with Applications
Example 1.7:
Solution:
True value,
f ' (x ) 15
. x 2 0.2 x 0.8
f '(0.5) 15
. (0.5)2 0.2 (0.5) 0.8 = 1.075
FDM:
BDM:
CDM:
0.5 ( 0.2625)
1525
.
0.5
41.9
( 0.2625) ( 0.7 )
0.875
0.5
18.60
0.5 ( 0.7 )
1200
.
10
.
11.63
f ' (0.5)
f ' (0.5)
f ' (0.5)
32
Numerical Methods
with Applications
Worksheet 1.6:
Solution:
True value,
f ' (x ) 15
. x 2 0.2 x 0.8
f '(0.5) 15
. (0.5)2 0.2 (0.5) 0.8 = 1.075
=>
=>
=>
f(xi) = -0.2625
f(xi-1) = -0.4984375
f(xi+1) = 0.0546875
t
FDM
BDM
CDM
( 0.0546875) ( 0.2625)
126875
.
0.25
18.02
f '( 0.5)
( 0.2625) ( 0.4984375)
0.94375
0.25
12.21
f '(0.5)
0.0546875 ( 0.4984375)
110625
.
0.5
f '(0.5)
2.91
We observe that the CDM is more accurate than the FDM and BDM. Also, halving the step size
approximately halves the error of FDM and BDM, and quarters the error of CDM.
End of Part One
33
Numerical Methods
with Applications
Checklist:
In part One, I have acquired the following knowledge and understanding:
Important formula/thing
Topics/Concepts
Y N
to remember
1. Objectives
2. Introduction to Numerical Methods:
a. Mathematical modeling
c. Error quantification
4. Approximation of function:
a. TSE
b. Remainder
34
Need
Guide
Numerical Methods
with Applications
35