Professional Documents
Culture Documents
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
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
1.0 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.
qo f (qi , c, u) (1-1)
F(t)
m
Applying Newton’s second law and neglecting the friction, we may write
2
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
F ma (1-2)
and for one-dimensional problem (as in this case), we can write eq(1-2) as
dv
m F (1-3)
dt
d 2x
or m F (1-4)
dt 2
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.
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 (1-5)
We can solve for the velocity at any time t, for example, at t = 2.0 s,
Numerical solution may be expressed using one of the standard formulas, such as forward finite
difference as follows.
3
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
yi 1 yi
vi (1-7)
ti 1 ti
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) 0 2 3
y (m) 0 19.62 44.145
t (s) 2 2.5
y (m) 19.62 30.65625
v (t = 2) = 22.0725 m/s
t (s) 2 2.1
y (m) 19.62 21.63105
v (t = 2) = 20.1105 m/s
t (s) 2 2.05
y (m) 19.62 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.
1. Provide extremely powerful problem-solving tools with the ability to handle large system of
equations, nonlinearities in the models, and complicated geometry.
2. Reinforce understanding of mathematics in describing the physical phenomena with the use of
computers.
3. Provide an insight and opportunity to analyze solution(s) of the problem from many different
4
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
perspectives.
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.
In general, engineering problem solving and analysis can be represented as shown in the diagram
below.
Problem
definition
Performance verification:
analytical/numerical methods,
statistics, computers, graphics, etc.
Implementation
5
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
(i) Significant Digits (s.ds) - those digits (or numbers) that can be used with confident plus one
estimated digit. For example:
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
0 5 2 9 7 0 watts
4
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.
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.
6
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
(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
Figure 1.5: Accuracy and precision
The accuracy of the numerical computation depends on a particular method used and on its ease
of implementation on the computer (i.e. accuracy and limitations of the computer). A computer
is used for two functions in regard to numerical computation: 1) to store numbers and 2) to
perform arithmetic operations. Computer can only store a finite number of digits. The remaining
digits are either chopped off or rounded off. This finite number representation in the computer
leads to an unavoidable error called a round-off error (REr).
Example of a computer program that supposedly reads and writes the same number:
Programming result,
input : 0.1234567890123
output : 0.1234567910433
7
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
In performing arithmetic operations, only certain digits are usually retained in order to get an
approximate solution. Several digits are truncated or omitted. These truncated digits lead to what
is called a truncation error (TEr).
Using the above programming result, the output A may be retained only up to 5 decimal places
(d.ps),
input : 0.1234567890123
Remark: 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
f ( x0 h ) f ( x0 )
mapprox f ' ( x0 ) (1-8)
h
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,
mtrue mapprox
f
f(x)
h
x0 x
x0 + h
when h is too small, REr dominates. This observation suggests that there must be an optimum
value of h .
(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,
which defines the error as the difference between the true value and the approximation.
Et x x * (1-10)
Note that the absolute error does not reflect the degree of its influence.
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.
9
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
x x*
Et , rel (1-11a)
x
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*
(True) Percent relative error : t x100% (1-11b)
x
(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.
x x*
( x*) (1-13)
x
( x*)
( x*) (1-14)
x
( x*)
( x*) (1-15)
x*
10
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
Next we would like to estimate the effect of the discrepancy between the true value and the
approximate value on the value of the function. This is called error propagation.
If a function f is dependent on
(a) a single independent variable x : f(x)
(b) two independent variables x and y : f(x, y)
(c) several independent variables x1 , x2 , x3 , ... ,xn : f(x1 , x2 ,..., xn ).
Truncating after the first derivative term and rearranging the remaining terms to give
f f f
f ( x1 *, x2 *,..., xn *) x1 * x2 * ... xn * (1-18)
x1 x2 xn
f f f
where , ,..., are partial derivatives of the function evaluated at points x1*, x2*,...,
x1 x 2 x n
and xn*.
11
Introduction to Numerical Methods Numerical Methods
and Error Analysis 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
Example 1.1: Knowing a value of x* = 2.0 with an error of x* = 0.01, estimate the resulting
error in the function
Using eq.(1-17) with the first derivative, f ' ( x ) 1.5 x 2 0.2 x 0.8
Therefore, we predict that the function value at x* = 2.0 would be in the range
f(2.0) = 4.5 0.064 or 4.436 < f(2.0) < 4.564 (error bounds)
12
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
Example 1.2: For a beam with one end fixed and the other end free (as shown below), the
deflection of the beam y is given by
FL4
F y
8 EI
(120)(27) 4
y* = 0.6710 ft (4 d.ps)
8(1.65x108 )(0.072)
y y y y
y(F*, L*, E*, I* ) F * L * E * I *
F L E I
0.045813
y = 0.6710 0.045813 ft
13
Introduction to Numerical Methods Numerical Methods
and Error Analysis 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.
x new x old
Ea (1-23a)
x new
x new x old
a x100% (1-23b)
x new
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)
s (0.5x10 2 p )% (1-25a)
E s (0.5x10 p ) (1-25b)
14
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
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.
Example 1-3: Exponential function using the Maclaurin1 Series expansion is given by
x 2 x3 xn
e x 1 x ...
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, e0.5 1.648721271 = 1.64...
x
1
Colin Maclaurin (1698-1746, 48), Scottish mathematician.
15
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
16
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
x
(x ) ( n 1)
Rn
x0 n!
f ( ) d (1-28)
where is a dummy variable. Note that Maclaurin series is a special form of Taylor series for
which x0 = 0.
2
Brook Taylor (1685-1731,46), English mathematician.
17
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
n
f ( k ) ( x0 ) k
f ( x)
k 0
k!
h Rn (1-29)
Note that 0! = 1.
f ( n 1) ( ) n 1
Rn h where x0 x (1-30)
(n 1)!
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.
zero-order : f ( x ) f ( x0 ) (1-31)
f '( x0 )
first-order : f ( x ) f ( x0 ) h (1-32)
1!
3
Joseph Louis Lagrange(1736-1813, 77), French-Italian mathematician and astronomer. A
successor of Leonhard Euler(1707-1783, 76)-born in Switzerland as director of Berlin Academy
in(1776).
18
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
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.
(a) with h = x - x0 = 1.0, 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
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
( 0)
4th-order approximation: f (1) 0.5 . ) 3 0.5
(10 and a = 0%.
4!
19
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
f(0.8) = 0.132
f’(0.8) = 1.6
f’’(0.8) = 2.2
f’’’(0.8) = 3.0
f(4)(x) = 0.0
(16. )
1st f (1) 0132
. ( 0.2 ) 0.452 9.6 70.8
1!
( 2.2 )
2nd f (1) 0.452 ( 0.2 ) 2 0.496 0.8 8.9
2!
(3.0)
3rd f (1) 0.496 ( 0.2 ) 3 05
. 0 0.8
3!
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%
( 0)
4th-order approximation: f (1) 0.5 . ) 3 0.5
(10 and a = 0%.
4!
20
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
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, f (5) (5) 4 0.7(5)3 2(5)2 (5) 62.5 = 420
( 302.975)
1st f (5) 238.775 ( 0.5) 7.08 38.8
1!
= 390.2625
(2201
.)
2nd f (5) 390.2625 ( 0.5) 2 0.530 6.59
2!
= 417.775
(1038
. )
3rd f (5) 417.775 (0.5)3 0.0149 0.515
3!
= 419.9375
( 24)
4th f (5) 419.9375 ( 0.5) 4 0.0 0.0149
4!
= 420
21
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
Remark: 1. The function and its n+1 derivatives are assumed to be continuous in the
interval of interest [x0, x].
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
f ( n 1) ( ) n 1
Rn h
( n 1)!
Despite these two drawbacks, we do however have control over two things:
1. the term hn+1 i.e. we can choose how far away from x0 we want to evaluate f(x).
2. the number of terms to be included in TSE.
22
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
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 Rn (h) : halving the step size h, will halve the error.
Rn ( h 2 ) : halving the step size h, will quarter the error.
Remark: 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. Let’s define an upper bound on the
magnitude of the reminder Rn such that
Rn Rn ,u (1-36)
with
M
Rn ,u h n 1 and f ( n 1) () M (1-37,38)
( n 1)!
Example 1-5: Recall the exponential function using the Maclaurin series example 1-3,
x2 x3 xn
ex 1 ...
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
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
Solution: Note x0 = 0.
f ( n 1) () n 1 e
The remainder Rn h x n 1
( n 1)! ( n 1)!
For x = 1.0, we have
1 1 1 e
f (1) e1 1 1 ... where 0 < < 1
2! 3! n! ( n 1)!
Defining,
e e
Rn
( n 1)! ( n 1)!
e e
Rn Rn,u (E1.5-1)
(n 1)! (n 1)!
3
Rn (0.5x10 p )
( n 1)!
24
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
Example 1.6: Use TSE from zero- through fifth-order to approximate the function,
1
f ( x)
x
at x = 2.0 with x0 = 1.0. Evaluate the true percent relative error for all cases.
1 3
Derivatives, f '( x ) x 2 => f’(1.0) = - 0.5
2
3 5 2
f ''( x ) x => f’’(1.0) = 0.75
4
15 7
f '''( x ) x 2 => f’’’(1.0) = - 1.875
8
(4 ) 105 9 2
f ( x) x => f (4)(1.0) = 6.5625
16
945 112
f ( 5) ( x ) x => f(5)(1.0) = - 29.53125
32
Order of approximations t %
25
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
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.
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 Introduction to Numerical Methods
with Applications and Error Analysis
Now h = x - x0 = 2.0 - 1.5 = 0.5 (which is half of step size in the previous example)
Order of approximations t %
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
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
Denoting xi = x0
xi+1 = x
f '( xi ) f ''( xi ) 2
with the remainder, Ro h h . . . Rn (1-40)
1! 2!
Ro f '( xi )h (1-41)
h
x xi+1 x
xi xi+1 xi
(a) (b)
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 Introduction to Numerical Methods
with Applications and Error Analysis
Thus, the slope f’() is equal to the rise Ro divided by the run h, or
Ro
f '( ) => Ro f '( ) h (1-42)
h
f ''( ) 2
R1 h (1-43)
2!
f '''( ) 3
R2 h (1-44)
3!
Using TSE and truncating after the first derivative term, we can write
f ( xi 1 ) f ( xi ) f '( xi )( xi 1 xi ) R1 (1-45)
f ( xi 1 ) f ( xi ) R1
f '( xi ) (1-46)
xi 1 xi xi 1 xi
st
1 order Truncation
approximation error
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 where h = xi+1 - xi
h 2!
R1
or ( h) (1-47)
h
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
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
There are three different methods for the approximation of the first derivative.
From eq.(1-45) and eq.(1-47) with h = xi+1 - xi , we may write eq.(1-45) in the form
Rearranging terms to give the finite difference formula for the first derivative as
f ( xi 1 ) f ( xi ) f i
f ' ( xi ) (h) or f '( xi ) (h) (1-49)
h h
TS can also be expanded backwards to approximate the previous value f(xi-1 ) based on the
present value f(xi ) as
Truncating all terms after the first derivative term and rearranging the equation yields
f ( xi ) f ( xi 1 ) f i
f ' ( xi ) ( h ) or f ' ( xi ) ( h ) (1-51)
h h
30
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
This can be derived by subtracting the backward TSE from the forward TSE which yields
Again solving for the first derivative and rearranging the terms to give
f ( xi 1 ) f ( xi 1 )
or f ' ( xi ) ( h2 ) (1-53)
2h
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 )
x x xi-1 x
xi xi+1 xi-1 xi xi xi+1
We will study numerical differentiation in more details in part Five. This includes the higher
accuracy formulas and also higher order derivatives.
31
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
Example 1.7: Use forward, backward and centered difference to estimate the first
derivative of the function
at x = 0.5 using a step size h = 0.5. Also calculate the true percent relative
error for each approximation.
t %
32
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
Worksheet 1.6: Use forward, backward and centered difference to estimate the first
derivative of the function
at x = 0.5 using a step size h = 0.25. Also calculate the true percent relative error for each
approximation.
t %
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.
33
Introduction to Numerical Methods Numerical Methods
and Error Analysis with Applications
Checklist:
3. Error analysis:
a. significant digits
c. Error quantification
4. Approximation of function:
a. TSE
b. Remainder
34
Numerical Methods Introduction to Numerical Methods
with Applications and Error Analysis
35