Ch1-Intro-Approximation-errors
Ch1-Intro-Approximation-errors
1
Basic operation performed by a
computer
• Arithmetic Operations: Addition,
subtraction, multiplication and division
• Logical operations: the sign or the
comparative magnitude of two numbers
• Data transfer: Moving data from one
location to another in the memory.
• Input-output operations: Controlling the
reading/writing of information into or out of
the computer
2
On Digital Computers
Digital computers store numbers in an entity (or
unit) called a word which consists of a string of
binary digits, or bits. Various number systems
are used to represent mathematical numbers.
Some commonly used number systems are:
hexadecimal (base 16), decimal (base 10), octal
(base 8), and binary (base 2). For example, in a
decimal system the number 8,410 is represented
in powers of ten as:
3
On Digital Computers (Cont’d)
A method known as the doubling procedure is as follows. Given a
decimal number N, it can be decomposed as:
Qk = 0 + Rk+1 etc.
B = Rk+1RkRk-1 ... R1
4
Example
Convert the decimal number N = 8,410, to a binary number.
Solution:
Perform sequential division by 2 as follows:
8,410 = (24,205) + 0 65 = (232) + 1
4,205 = (22,102) + 1 32 = (216) + 0
2,102 = (21,051) + 0 16 = (28) + 0
1,051 = (2525) + 1 8 = (24) + 0
525 = (2262) + 1 4 = (22) + 0
262 = (2131) + 0 2 = (21) + 0
131 = (265) +1 1 = (20) + 1
5
Representations of Numbers
6
Significant Digits
Note that the zeros which are used only to shift the decimal point
are not counted as significant figures. The leading zeros may or
may not be significant. For example,
x = 0.0002815 has 4 significant figures!
x = 1,200 may have 4, 3, or 2 significant figures!
8
Computer Representation of Numbers
{sign} Value
1 0 0 0 1 0 1 1
9
Example
10
Floating-Point Representation
x = (sign)m.b(sign)E
d1 d2 d3 d4 d5 d6 d7 d8
11
Example
0 0 0 0 1 1 1 1
Solution:
m = +(023 + 022 + 021 + 120)
m = +( 0 +0 + 0 + 1 )=1
E = -[(121) + (120)] = -(2+1) = - 3
Number = 12-3 (which is equal to 0.1250 in decimal system)
12
Errors
13
Errors
14
Errors (Cont’d)
For series, sequences, and iterations, approximate error can be defined as:
Approximate absolute error (for iterative calculations):
When the exact value of a quantity is not given (or known), it is not possible
to calculate a true error. However, the approximate error can be used to
calculate error bounds for an approximate answer. To this end, a theorem
called Scarborough criteria can be very useful.
Scarborough Criteria
If the approximate relative error, ea < 0.510-m, then the result (or the
answer) is correct to at least m significant digits.
15
Example E1.5.1
Calculate the number of terms that is necessary to estimate the
value of to two significant digits from the Taylor series expansion
for Arctan(x) about the base point x = 0. The number =
3.141592653589793 (to 16 significant digits) is related to this
function by:
= 4.0Arctan(1.0)
Solution:
The infinite series (convergent in the range –1.0 to 1.0) is given by:
n 1
Arc tan x x
x 3 x 5 x 7 x 9 x11
...
1 x 2 n 1
...
3 5 7 9 11 2n 1
where n = 1, 2, 3, ...
Check your answer by actually calculating from the above series.
Plot the true relative error and the approximate relative error as a
function of the number of terms.
16
Errors (Cont’d)
Solving this equation for n (by trial and error) gives: n 130
17
MatLab solution
18
Comparison of the true and approximate
relative error
19
Computer errors: Round off or Chop off errors
20
Computer errors: Round off or Chop off errors
Subtractive cancellation
This error occurs when subtracting two nearly equal numbers. Let us further
explain this with an example.
Example
If x = 40,000.01 and y = 40,000, what is x minus y using a 3-digit mantissa?
Solution:
0.4000001x105
-0.4000000x105
_______________________
21
Example E1.5.5
The results with t = 0.1 and 0.001 sec are depicted in figure along with the
exact solution :
T = Ta + (T0 - Ta)exp(-t/h)
22
Figure E.1.5.5 Illustration of smearing due to
round off
23
Truncation error
Truncation errors are those which usually arise from neglecting (cutting) a number of terms in a
series formulation.
when x = 0.5, the exact value of (x) = 2. If we represent this function by only three terms (n =
2), then:
(0.5) 1 + x + x2 = 1 + 0.5 + (0.5)2 = 1.75
This truncation error is the sum of all the terms left out from the infinite series.
(x) = 1/(1 - x) 1 + x + x2 + (T.E.)n=2
24
Taylor series expansion & approximation
25
Determining of converges
26
Example E.1.6.1
27
Approximation of Functions: Taylor Series
where (n)(a) denotes the nth order derivative of with respect to the
independent variable x, then, evaluated at the point x = a. The point x = a
about which the expansion is built is known as the base point.
If the Taylor series is truncated after a finite number of terms, then the sum
of all the terms truncated is called the remainder Rn(x). That is:
28
Taylor Series
The remainder Rn(x) can be written (Stein, 1967) in the integral form as:
x
( x t ) n f ( n 1) (t )dt
Rn ( x)
a
n!
f ( x)dx (b a) f ( ) ; a b
a
b b
f ( x) g ( x)dx f ( ) g(x) ; a b
a a
Rn ( x ) ; a x
(n 1)!
29
Taylor Series (Cont’d)
In Taylor`s Theorem, let a = xi (meaning the ith point) and let x = xi+1 = a+h = xi+h
denote the next point. Then it takes the form:
This form is particularly convenient for developing finite difference formulae. This
equation can be further simplified with a change of notation:
i = (xi); i+1 = (xi+1); i(n) = (n)(xi)
This form is convenient in deriving formulae for the integration of ordinary differential
equations (see Chapter 6).
Some simple formulae for computing the derivative of a function numerically are
given here as an introduction to numerical differentiation. 30
Numerical differentiation
We truncate the Taylor series after the second term and solve for (1) = to obtain:
= (i+1-i)/h
or
df f ( xi 1 ) f ( xi ) f (a h) f (a )
S f ; Forward Difference
dx x xi xi 1 xi h
where h = xi+1-xi = x. This is called a first order, forward difference approximation for the first
derivative at the point x = xi = a. Note that the fundamental definition of the derivative of a
function is:
df f x h f x
lim
dx h 0 h
Hence, Sf should become more and more accurate as we make the step size h smaller and
smaller. However, one must be careful with round off errors
Other formulae can also be derived with the help of Taylor series expansion. (see fig. below)
df f ( xi ) f ( xi 1 )
Sb
dx x xi xi xi 1
; Backward difference
df f ( xi 1 ) f ( xi 1 )
S c ; Central difference
dx x xi xi 1 xi 1 31
Graphical interpretation of finite difference
Sb
fi
y fi 1 Sc
Sf
fi 1
y f (x)
h h
xi 1 xi xi 1 x
32
Application of Taylor Series
Example:
Using Taylor series, expand the function (x) = ln(1+x) about the base point a = 0. Also, using Taylor's formula, approximate
this function as a first, second, and third degree polynomial. Compute ln(1.5) from the Taylor series with increasing an number
of terms and make a table of the true and approximate errors as a function of the number of terms used in the summation.
Further, estimate the truncation error.
Solution:
(x) = ln(1+x)
(x)
(1)
= 1/(1+x)
(x)
(2)
= -1/(1+x)2
(3)(x) = (2)(1)/(1+x)3
(x)
(4)
= -(3)(2)(1)/(1+x)4
. .
(n)(x) = (-1)n+1(n-1)!/(1+x)n
x n 1
R lim n n 1 x
n x
n 33
Application of Taylor Series (Cont’d)
These approximate functions are plotted in the figure below in comparison with the
original function, (x) = ln(1+x). It is seen that as we take more and more terms, the
approximate function (polynomial) represents the original function better and better in
the neighborhood of the base point x = a = 0.
34
Application of Taylor Series (Cont’d)
35
Figure: Taylor series approximation to (x) = ln(1+x).
Case Study
36
Case Study (Cont’d)
Numerical results for parts (a.), (b.), and (c.) are tabulated in Tables C1.7.1a-c, and shown in Figures
C1.7.1a-c. For case (b.), note that (x) = eln(x) = x. Hence, df/dx = 1.0. We obtain the exact derivative with any
value of h that is not very small so that the round off error becomes significant. When h becomes very small,
we are adding a small number h to a large number that cannot be handled by the computer. For example, for
small h:
37
Case Study (Cont’d)
Table: Variation of the True Error with Step Size for Calculating the Derivative of (x) = Cos(-10x2)
Exact Derivative = 0.000000E+00
Numerical Derivative at x = 0.000000E+00
h df/dx True Error
1.000000E+00 -1.839072E+00 1.839072E+00
1.000000E-01 -4.995835E-02 4.995835E-02
1.000000E-02 -4.999999E-05 4.999999E-05
9.999999E-04 -4.999999E-08 4.999999E-08
9.999999E-05 -5.000016E-11 5.000016E-11
9.999999E-06 -4.878910E-14 4.878910E-14
9.999999E-07 0.000000E+00 0.000000E+00
9.999999E-08 0.000000E+00 0.000000E+00
9.999999E-09 0.000000E+00 0.000000E+00
9.999999E-10 0.000000E+00 0.000000E+00
9.999999E-11 0.000000E+00 0.000000E+00
40
References
• Celik, Ismail, B., “Introductory Numerical Methods for Engineering Applications”,
Ararat Books & Publishing, LCC., Morgantown, 2001
• Fausett, Laurene, V. “Numerical Methods, Algorithms and Applications”, Prentice
Hall, 2003 by Pearson Education, Inc., Upper Saddle River, NJ 07458
• Rao, Singiresu, S., “Applied Numerical Methods for Engineers and Scientists, 2002
Prentice Hall, Upper Saddle River, NJ 07458
• Mathews, John, H.; Fink, Kurtis, D., “Numerical Methods Using MATLAB” Fourth
Edition, 2004 Prentice Hall, Upper Saddle River, NJ 07458
• Varol, A., “Sayisal Analiz (Numerical Analysis), in Turkish, Course notes, Firat
University, 2001
41