You are on page 1of 38

GEM501E

9/18/2017 1
GEM 501E

Instructor: Assoc.Prof.Dr. Uur Oral nal, Room

#110, email:ounal@itu.edu.tr
Homework: 3 or 4 pieces of homework are to be
meticulously prepared. Submission (on time) is
compulsory for the final exam qualification.
Exams: 1 midterm exam (probably in the 7th or 8th
week) and a final exam.
Grading: 30% homework, 30% midterm, 40% final

9/18/2017 2
Error Analysis and
Interpolation

9/18/2017 3
Approximate Numbers
a0 : exact value
a : approximate value (Ex: 1/3 and 0.33)
a a0 a
is the absolute error of a

Example: If a=0.387 and a=0.01, then the 3rd

digit is meaningless. Should be correctly
written as: a=0.39

9/18/2017 4
Approximate Numbers
In the error analysis the relative error may be
defined as follows:
a
a
A0

, A0 0
Relative error is related with the number of
significant (meaningful) digits. For the previous
example:
0.0045 %0.45
0.0926
a
20.7426

9/18/2017 5
Significant Digits
The absolute error of a number, which is
correctly given, cannot be larger than the
half of the value of the last digit.

For example; if e=2.718 is correctly given,

the absolute error is e0.0005. Here we have
3 significant digits after the decimal point.

9/18/2017 6
Absolute errors (uncertainties)
0.02 e0.005
3.1245 e0.00005
2.8 e0.05
5.0 e0.05
2. e0.5
123 not defined

9/18/2017 7
Arithmetic operations with
approximate numbers
The absolute error of the sum (or difference) of
multiple approximate numbers is the sum of the
absolute error of each number
S a1 a2 an
s a1 a2 an
If all ais have the same sign, the relative error of the
sum S (s) cannot be larger than the largest of the
relative errors of these terms:
min ai s max ai , i 1,2,, n
9/18/2017 8
Arithmetic operations with
approximate numbers
The relative error of the difference of two positive
numbers is larger than the relative errors of these
numbers

For the multiplication and division of the

approximate numbers the relative errors of the
terms are summed:
a1 a2 am
r ; z xm yn
b1 b2 bn
r a a a b b b
1 2 m 1 2 n

z m x n y
9/18/2017 9
Errors in the calculation of function values

The absolute error in y=f(x) due to the x error in x:

y f ( x) x

Relative error:

f ( x)
y x ln f ( x) x
f ( x)

9/18/2017 10
Errors in the calculation of function values

For the calculation of the absolute error of

multivariable functions such as y=f(x1,x2,..,xn), if x1,
x2,..,xn are small enough:
n
f 1 f
y xi and y xi
i 1 xi i f xi

9/18/2017 11
Errors in the calculation of function values
Besides these rounding errors other rounding errors
can occur due to the use of binary system.
This can be partly minimised with the use of double
precision in the computational analyses.

9/18/2017 12
Errors in the calculation of function
values
Example
If the uncertainties in y and a are given as 0.1 and
1, respectively, calculate the absolute error of the
function, f=y cos(a) for y=3.0 and a=40 (degrees).
n
f
i 1 xi
i

/=cos(a); f/a=-y sin(a)

f=|cos(a)|* y+|y sin(a)|x a=cos40x0.1+3xsin40x0.017=0.11
f=(2.3 0.1) or f= 2. without indicating the uncertainty value, since,
f<0.5

9/18/2017 13
Conditionedness in Functions
Let us define the maximum relative change in a function f(x) due to a small
change in the value of x:

If a function has a value of 0 at some point its conditionedness or condition

number- (co) at that point will be infinite. This means that small changes in x will
cause large changes in f(x).
If the co gets larger, the function becomes an ill-conditioned function.

Example:

co

9/18/2017 14
Conditionedness in Functions
Example:
If f(x)=ex cox (What does this mean?)
Example:

around = 1 it is ill-
conditioned

9/18/2017 15
Numerical Instability
Numerical instability is a measure of how a rounding error is effective on the
result of a calculation.
Example:
Let us perform the calculation with 6-digit arithmetic

f(12345)=0.00450003 is the true value.

However, 6-digit arithmetic gives f(12345)=0.005 !!

Caution: The co of the function is around 0.5. This can be validated by assigning
an arbitrary value to x. However, we are not dealing with this but the effect of
the rounding in the mathematical operations on the result!
If we treat the function as F(t)=a-t, when ta, the result goes to zero. The
conditionedness of the function F(t) can be obtained as |t/t-a)|. When t a the
conditionedness goes to infinity which means that a small change in t will make
a large difference in the result.
9/18/2017 16
Truncation errors
Arises from the use of finite series instead of
infinite ones

infinite series - correct

Infinite: Finite:

9/18/2017 17
Truncation errors
Let us recall Taylor expansion and error formula

If f(x) is continuous and their (n+1)th order derivative exist

within [x,x0]:
n
f i x0
f x x x0 Rn x
i

i 0 i!
f n 1
Rn x x x0
n 1
; x0 x or x x0 ;
n 1 !

9/18/2017 18
Discretisation Errors
GCI (grid convergence index)

or for 2D: h is the

characteristic mesh
size

Let us calculate the apparent order

of the discretisation method:

Here, for r=constant q(p)=0.

9/18/2017 19
Discretisation Errors
GCI (grid convergence index)
The extrapolated values can be calculated.

The grid convergence index for the fine

mesh

9/18/2017 20
Discretisation Errors
GCI (grid convergence index)

Sample Calculations

9/18/2017 21
INTERPOLATION

Exact Approaches

Piecewise Approaches (Spline Interpolation)

9/18/2017 22
INTERPOLATION
-Exact Approaches-
The problem is to find a P(x) function that exactly
satisfies the values of f(x) at the discrete points xi
(P(xi)=f(xi)).

According to Weierstrass Theorem, if f(x) is continuous

in the closed interval [a,b], then, there exists a
polynomial function, Pn(x), of degree n, such that:
f ( x) Pn ( x) , n n( )

9/18/2017 23
INTERPOLATION
-Exact Approaches-
Basically, the exact approaches have three
different versions:
Newtons divided-difference polynomials
Lagrange polynomials
Finite-difference polynomials (for equidistant
nodes)

9/18/2017 24
INTERPOLATION
-Exact Approaches-
-Divided-difference polynomials-
o f x Pn x Rn x
o Pn x f x0 x x0 f x1 , x0 x x0 x x1 f x2 , x1 , x0
x x0 x x1 x x2 f x3 , x2 , x1 , x0
x x0 x x1 x xn 1 f xn , xn 1 , , x1 , x0

o Rn x x x0 x x1 x xn f x, xn , xn 1 , , x1 , x0
x0 x xn

n f n 1
Rn x x xi , x, xn , xn 1 , , x0
o

i 0 n 1 !
9/18/2017 25
INTERPOLATION
-Exact Approaches-
-Divided-difference polynomials-
f x1 f x0
o
f x1 , x0 f x0 , x1
x1 x0

f x2 , x1 f x1 , x0
o f x2 , x1 , x0 f x1 , x0 , x2 f x0 , x2 , x1
x2 x0

o f x , x , , x f xn , xn 1 , , x1 f xn 1 , xn 2 , , x1 , x0

n 1
xn x0
n 0

9/18/2017 26
INTERPOLATION
-Exact Approaches-
-Lagrange Polynomials-

f x Pn x Rn x
n
Pn x Li x f xi
i 0

Li x
x x0 x x1 x xi 1 x xi 1 x xn
xi x0 xi x1 xi xi 1 xi xi 1 xi xn
L x
xx
n
j
i
x x
j 0 i j

f n 1
j i
n
Rn x x xi , x, x0 , x1 , , xn
i 0 n 1 !

9/18/2017 27
INTERPOLATION
-Exact Approaches-
-Lagrange Polynomials-
Lagrange polynomials are in fact obtained from divided-
difference polynomials. For example:

P2 x f x0 x x0 f x1 , x0 x x0 x x1 f x2 , x1 , x0

P2 x

9/18/2017 28
INTERPOLATION
-Exact Approaches-
-Finite-Difference Polynomials-

Used when the nodes are equidistant.

Forward differences

Backward differences

Central differences

9/18/2017 29
INTERPOLATION
-Exact Approaches-
-Finite-Difference Polynomials - Forward Differences-
E f xi f xi h f ( xi 1 )

f x f xi 1 f xi
The relationship with the shift
operator and the forward
difference operator is defined

E 1
n n in this manner.

9/18/2017 30
INTERPOLATION
-Exact Approaches-
-Finite-Difference Polynomials - Forward Differences-
f x Pn x Rn x
with
x x0

h

1 1 2 1 2 n 1
Pn f 0 f 0 2 f 0 3 f 0 n f 0
2! 3! n!
n
!
Pn x0 h i f 0
i 0 i !i!

1 2 n 1 2 n
Rn x0 h h n 1 f ( n 1) ( ) n 1 f 0
n 1! n 1!
9/18/2017 31
INTERPOLATION
-Exact Approaches-
-Finite-Difference Polynomials Backward Differences-

E f xi f xi h f ( xi 1 )

f x f xi f xi 1 The relationship with

the shift operator and
the backward difference

1 E
n

1 n operator is defined in
this manner.

9/18/2017 32
INTERPOLATION
-Exact Approaches-
-Finite-Difference Polynomials Backward Differences-

f x Pn x Rn x
with
x x0

h
1 1 2 n 1
Pn f 0 f 0 2 f0 n f0
2! n!

f n 1
Rn 1 n h n 1 ; x n x0
(n 1)!

n ( f 0 )
Rn 1 n
(n 1)!
9/18/2017 33
INTERPOLATION
-Exact Approaches-
-Finite-Difference Polynomials Central Differences-
E f xi f xi h f ( xi 1 )

f x f xi 1/ 2 f xi 1/ 2 The relationship with

the shift operator and
the central difference
E
n 1/ 2
E
1 / 2 n operator is defined in
this manner.

9/18/2017 34
INTERPOLATION
-Exact Approaches-
-Finite-Difference Polynomials Central Differences-
Different formulations may be used.
For instance, by using Gauss forward central difference polynomial:

f x Pn x Rn x
with
x x0

h
1 1 1
f f x0 f x0 h 2 f x0
2
3 f x0 h 2
2! 3!

n ( f1/ 2 )
Rn 1 (n 1) n is even
(n 1)!

n ( f 0 )
Rn 1 1 (n 1) n is odd
(n 1)!
9/18/2017 35
INTERPOLATION
- Approximate Approaches- Least Squares
The squares of the error should be calculated:
2
N 2 N
n
E Pn xi f xi a j xi f xi
j

i 0 i 0 j 0
The coefficients aj of the polynomial that makes the error minimum is to
be found:
E
0
a j

The error is given in statistical manner such as correlation coefficient or

standard deviation.

9/18/2017 36
INTERPOLATION
- Piecewise Approaches- Spline Interpolation
Third-order polynomials are to be
produced for all sections

At the node points the following conditions are to be satisfied.

For natural spline, at the boundaries:
Si-1(ti)=Si(ti)
S(ti-1)=S(ti+n)=z1=zn=0
Si-1(ti)=Si(ti)

(hi=ti+1-ti)

and we obtain:

9/18/2017 37
INTERPOLATION
- Piecewise Approaches- Spline Interpolation
An equation system is obtained and the second derivatives zis can be
found.

h=max|xi+1 -xi|

9/18/2017 38