Error Analysis in Numerical Methods
Error Analysis in Numerical Methods
Solutions to a math problem can be classified into two types: 1) Analytical solution: an
exact answer in the form of a mathematical expression in terms of the variables
associated with the problem. 2) Numerical solution: an approximate numerical value (a
number) for the solution.
For a problem to be solved numerically, you may choose several numerical methods
which differ in accuracy, time of calculation. Numerical methods are mostly
implemented in a computer program (such as MATLAB, C++), we need to know how to
represent number on a computer.
15
Upper limit = 214+ 213 + . . . + 22+ 21 + 20 = 215 - 1 = 32,767
How does computer store floating-point number? Sign, Biased exponent, Mantissa,
i.e. mantissa in binary form, exponent added by bias and in binary form.
sign biased exponent mantissa
Sign
exponent+ bias (127) Mantissa
1
8 bits 23 bits
bit
Range:
Sign
exponent + bias (1023) Mantissa
1
11 bits 52 bits
bit
Range:
Since numerical solutions are approximated results, we have to specify how different the
approximated results are from the true values, i.e. how large the error is.
The difference between the true value and the approximated value is error. Error can be
estimated in three ways:
16
1). True Error: The difference between the true solution value and the approximated
(numerical) solution value,
2). True Relative Error: The percentage of the numerical error over the true value,
3). Estimated Relative Error: For some problem, the true solution is not known,
calculations for a numerical solution are executed in an iterative manner until a
desired accuracy is achieved, then estimated relative error is used as a standard to
check the solution. The percentage of the difference between the current
approximation and preceding approximation over preceding approximation is defined
as approximation error,
current approximation - preceding approximation
a 100%
current approximation
Example 2.2 Determine the true relative error and estimated relative error from
x2 x3
approximating of e by using the series e 1 x
0.5 x
up to 6th term. And
2! 3!
write MATLAB code to display the all the true relative errors for each approximation.
true value: >> format long ; exp(0.5)
>> ans =
1.648721 . . .
17
MATLAB code for plotting the true relative error VS terms kept:
40
35
30
25
20
15
10
0
1 2 3 4 5 6
Example 2.3 Display π in short, long and long scientific format with MATLAB.
>> format short ; pi
>> ans = 3.1416 (short data has 5 digits)
Error resulted from omission of the remaining significant figures is called round-off
error.
18
2.3.2 Truncation Errors
Example 2.4 The velocity with respect to time of bungee jumper is given in the 1st-
order differential equation as below. Compute velocity of a free fall bungee jumper
with a mass of 70 kg. Use a drag coefficient of 0.25 kg/m.
dv C
g d v2
dt m
where v = vertical velocity (m/s), t = time (s), g = gravity acceleration ( @ 9.81 m/s2)
cd = drag coefficient (kg/m), m = jumper’s mass (kg).
Analytical Method:
MATLAB code:
60
50
40
30
20
10
0
0 2 4 6 8 10 12
Numerical Method:
Rate of change of velocity can be approximated by
dv v v(t i 1 ) v(t i )
dt t t i 1 t i
2
Substitute dv/dt = g – (cd/m)v into above to give
19
Rearrange equation to yield
MATLAB code:
t(s) v(m/s)
0 0
2 19.62
4 36.49
6 46.60
8 50.71
10 51.96
12 52.30
60
50
40
30
20
10
0
0 2 4 6 8 10 12
20
From the above example, we find that
f ( n 1) ( ) n 1
Rn h where xi xi 1
(n 1)!
If the Taylor series is truncated after term n+1, then f(x+h) is approximated by
f ' ' ( x i ) 2 f ' '' ( x i ) 3 f ( n ) ( xi ) n
f ( xi 1 ) f ( xi ) f ' ( xi )h h h h
2! 3! n!
The n+1th order truncation error is
f ( n 1) ( ) n 1
Rn h O(h n 1 )
(n 1)!
Where ξ is not known but lies somewhere between xi and xi+1.
21
Example 2.6 Plot the Taylor series approximation of f(x)=sin(x) from n=1 to n=4 in
MATLAB.
MATLAB code:
>> x = -2*pi:pi/30:2*pi;
>> y = sin(x);plot(x,y)
>> axis([-2*pi 2*pi -1.5 1.5])
>> hold on
>> y1 = x; plot(x,y1,'-o')
>> y2 = x-x.^3/6; plot(x,y2,':')
>> y3 = x-x.^3/6+x.^5/120; plot(x,y3,'-x')
>> y4 = x-x.^3/6+x.^5/120-x.^7/120/42; plot(x,y4,'.-')
>> legend('sin(x)','n = 1','n = 2','n = 3','n =4')
1.5
sin(x)
n=1
1 n=2
n=3
n =4
0.5
-0.5
-1
-1.5
-6 -4 -2 0 2 4 6
22
Example 2.7 Use Taylor series expansions with n = 0 to 6 to approximate f(x) =
cos(x) at xi+1 = π /3 on the basis of the value of f(x) and its derivatives at xi = π /4.
First-order approximation:
f(π /3) ≈
Second-order approximation:
f(π /3) ≈
0
0.707106781 41.4
1
0.521986659 4.40
2
0.497754491 0.449
3
0.499869147 2.62 x 10-2
4
0.500007551 1.51 x 10-3
5
0.500000304 6.08 x 10-5
23