You are on page 1of 76

Interpolation

Dr. Wan Fathul Hakim W. Zamri


PM Dr. Zainuddin Sajuri

www.ukm.my

What is interpolation?

Why interpolation is so
important?

www.ukm.my

data

Objective: to predict the value between a set of data


www.ukm.my

Interpolation vs Curve
Fitting
With interpolation we seek a function that
allows us to approximate such that functional
values between the original data set
values may be determined(estimated).
With curve fitting we simply want a function
that is a good fit (typically a best fit in
some sense) to the original data points.
With curve fitting the approximating function
does not have to pass through the original data
set.
4

Introduction

www.ukm.my

Example of Interpolation

Why I have to learn interpolation at


Mechanical Engineering?

Type of interpolation
Linear
st
(1st
order)

Quadrati
nd
c (2nd
order)

Polynomi
al (norder)

Newton:
Finite Divided
Difference

st order
1st

nd order
2nd

Linear

Lagrange

Quadr
atic

Spline

Cubic

Multivar
iable

Interpolation

www.ukm.my

Interpolation

A. Newton Interpolation:
Finite Divided Difference

Linear (1st
order)
Newton:
Finite Divided
Difference

Quadratic (2nd
order)
Polynomial (norder)

www.ukm.my

a. Newton Interpolation:
Finite Divided Difference
(Linear)

www.ukm.my

10

How to solve it based on your


previous knowledge
(Thermodynamics course)?
Axes\Poi Start
nt
xo

Mid
x

End
x1

10

20

80
www.ukm.my

11

Example 3.1
We only know two
points

www.ukm.my

Axes\Poi star
nt
t

mid end

y=lnx
0
Axes\Poi star
nt
t

?
1.791
75
mid end

y=lnx

1.386
2

12

Source: University of Waterloo,


Canada

Linear polynomial
13

Example

Linear polynomial
14

Relative error

*calc.= measured ; *exp =


actual

www.ukm.my

15

Conclusion: Newton-Linear???

www.ukm.my

16

Exercise 1
x
1

y=3lnx
6
0
5
f(x) = 3 ln(x) + 0
2.0794
R = 1
4
2
42
3.2958
3
3
37
2
4.1588
1
4
83
4.8283
0
0
1
2
3
4
5
6
5
14
5.3752
6
78approximate value of y(3) using linear
Calculate
an
interpolation using the following ranges
a) x=2 and x=4 where f(2) = 2.079442 and f(4) =
4.158883
b) x=2 and x=5 where f(2)= 2.079442 and f(5) =
4.828314
https://www.youtube.com/watch?
v=MCVqOwtAFRM&index=2&list=LLnT3nvYwbs8HI0Yze5u2Ktw

17

The comparison results between the


types of interpolation

18

b. Quadratic interpolation
If three data points are available, the estimate is improved
by introducing some curvature into the line connecting the
points.

www.ukm.my

19

Example 3.2

Axes\Poin
t

x0

x1

x2

y=lnx

1.386 1.79

www.ukm.my

20

Source: University Waterloo, Canada

Quadratic polynomial

21

Example

22

Answer 3.2

www.ukm.my

23

Result: What is the problem?

24

Exercise 2
x
1
2
3
4
5
6

y=3lnx
0
2.0794
42
3.2958
37
4.1588
83
4.8283
14
5.3752
78

6
5

f(x) = 3 ln(x) + 0
R = 1

4
3
2
1
0

Calculate an approximate value of y(3) using linear interpolation


using the following ranges
a) x=2 , x=4 and x=5 where f(2) = 2.079442 , f(4) = 4.158883,
f(5) = 4.828314
b) x=1 , x=5 and x=6 where f(1)= 0 and f(5) = 4.828314, f(6)=

25

c. Polynomial (n-order
interpolation)
The general form representing an n-th order interpolation
function (requires
n+1 pairs of data) is:

www.ukm.my

26

www.ukm.my

27

Source: University of Waterloo,


Canada

Cubic polynomial
28

Example

29

Source: University of Waterloo,


Canada

Quartic polynomial
30

Example 3.3: Assignment

Axes\Po
int

x0

x1

x2

x3

y=lnx

1.38 1.60 1.79


6
9

www.ukm.my

31

Answer 3.3

www.ukm.my

32

Summary: General Form of Newton Interpolation


f n ( x) f ( x0 ) ( x x0 ) f [ x1 , x0 ] ( x x0 )( x x1 ) f [ x2 , x1 , x0 ]
( x x0 )( x x1 ) ( x xn 1 ) f [ xn , xn 1 , , x0 ]
b0 f ( x0 )
b1 f [ x1 , x0 ]
b2 f [ x2 , x1 , x0 ]

f 2 ( x) b0 b1 ( x x0 ) b2 ( x x0 )( x x1 )
x x0

b0 f ( x0 )

x x1

b1

bn f [ xn , xn 1 , , x1 , x0 ]
f [ xi , x j ]

f ( xi ) f ( x j )

f [ xi , x j , xk ]

x x2

xi x j

f ( x1 ) f ( x0 )
x x0

f ( x2 ) f ( x1 ) f ( x1 ) f ( x0 )

x2 x1
x1 x0
b2
x 2 x0

f [ xi , x j ] f [ x j , xk ]
xi xk

f [ xn , xn 1 , , x1 , x0 ]

f [ xn , xn 1 , , x1 ] f [ xn 1 , xn 2 , , x0 ]
x n x0

f1 ( x) f ( x0 ) f ( x1 ) f ( x0 )

x x0
x x0
f1 ( x) f ( x0 )

www.ukm.my

f ( x1 ) f ( x0 )
( x x0 )
x x0
33

Newton

f1 ( x) b0 b1 ( x x0 )
f 2 ( x) b0 b1 ( x x0 ) b2 ( x x0 )( x x1 )

f 3 ( x) b0 b1 ( x x0 ) b2 ( x x0 )( x x1 ) b3 ( x x0 )( x x1 )( x x2 )

www.ukm.my

34

Exercise 3
Given the following data table,
evaluate
f(2.4)using3rdorder
Newton's
Divided
Difference
interpolation polynomial.
x

y=f(x)

2.25

3.75

4.25

5.81

35

Interpolation

B. Lagrange
Interpolation

1
order
nd
2
order
st

Lagrange

www.ukm.my

36

Lagrangian Interpolation
The Lagrange interpolating polynomial is
simply a reformulation of the Newtons
polynomial that avoids the computation of
divided differences:
n

f n ( x) Li ( x) f ( xi )
i 0
n

Li ( x)
j 0
j i

x xj
xi x j
www.ukm.my

37

38

What are the different?

Newto
n

f1 ( x) f ( x0 ) f ( x1 ) f ( x0 )

x x0
x x0

f ( x1 ) f ( x0 )
f1 ( x ) f ( x0 )
( x x0 )
x x0

f1 ( x )

x x0
x x1
f ( x0 )
f ( x1 )
x0 x1
x1 x0

Lagrangi
an

x x0 x x2
x x1 x x2
f 2 ( x)
f ( x0 )
x0 x1 x0 x 2
x1 x0 x1 x 2

x x0 x x1

f ( x2 )
x2 x0 x2 x1
www.ukm.my

f ( x1 )

39

First order Langrange

www.ukm.my

40

Second order Lagrange

www.ukm.my

41

Exercise 4
A) Newton and B) Lagrangian

42

Week 5

43

The night life


http://www.youtube.com/watch?v=CzReZ-kjGKo

44

Interpolation

C. Spline Interpolation

Linear

Spline

Quadratic

Cubic

www.ukm.my

45

Spline Interpolation
There are cases where polynomials can lead to
erroneous/inaccurate results because of round
off error and overshoot.
Alternative approach is to apply lower-order
polynomials to subsets of data points. Such
connecting polynomials are called spline
functions.

www.ukm.my

46

A visual representation of a
situation where splines are
superior to higher order
interpolating polynomials. (a-c):
indicate that the unexpected
changes induces oscillations in
interpolating polynomials. (d)
cubic spline much more
acceptable approximation since
it is limited to third-order
curves with smooth transitions

example
47

www.ukm.my

48

1. Linear spline

49

Example 3.6
X=
5

50

Result 3.6: Linear spline

X=5

www.ukm.my

51

4
4 STEPS
STEPS FOR
FOR SOLVING
SOLVING QUADRATIC
QUADRATIC
SPLINE

2. Quadratic spline

52

Result 3.7: Quadratic spline

www.ukm.my

53

Example: Quadratic spline

54

Number of
Unknown= 3n where
n is interval
Number of condition=
3n -2 where n is interval

20.25a1+4.5b1 + c1 =1.0
20.25a2+4.5b2+c2=1.0
49a2+7b2+c2=2.5
49a3+7b3+c3=2.5

X=
3

X=4.
5

X=7.
0

X=9.

Inside the
Boundary

9a1+3b1+ c1 =2.5
81a3+9b3+ c3=0.5

X=
3

X=9.
0
Outside the
Boundary 56

9a1 +b1=9a2+b2
14a2+b2=14a3+b3

X=
3

X=4.
5

X=7.
0

X=9.
0
Derivatives
-Inside the
Boundary

57

20.25a1+4.5b1 + c1 =1.0
20.25a2+4.5b2+c2=1.0
49a2+7b2+c2=2.5
49a3+7b3+c3=2.5
9a1+3b1+ c1 =2.5
81a3+9b3+ c3=0.5
9a1+3b1+ c1 =2.5
81a3+9b3+ c3=0.5

58

3. Cubic spline

59

Cont..

www.ukm.my

60

Example 3.8

Hey brother
http://www.youtube.com/watch?v=YxIiPLVR6NA
www.ukm.my

61

answer

62

Result 3.8

www.ukm.my

63

Multivaria
ble
Interpolati
on

64

d. Multivariable
Interpolation
st
Linear
Linear (1
(1st
order)
order)

Quadratic
Quadratic
nd
(2
(2nd
order)

Polynomi
Polynomi
al
al (n(norder)

Newton:
Finite Divided
Difference

st order
1
1st
order

nd order
2
2nd
order

Line
ar

Lagrange

Quad
ratic

Spline

Cubi
c

Multiv
ariable

Interpolation

www.ukm.my

65

www.ukm.my

66

Example 3.10

www.ukm.my

67

Solution
xy

0.2

0.3

0.4

1
1.
5
1.
5
1.
5
1.

0.5

0.64
9
1.00
3
1.35
9
1.70
3

0.2 0.99
1.52
0.3
4
2.04
0.4
5
2.54

Y=0.3
3

Y=0.3
3

Y=0.3
3

68

Use this concept

Estimate value of z at x =0.6


and y =0.33
69

xy

0.2

0.3

0.4

1
1.
5
1.
5
1.
5
1.
5

0.5

2
2

0.64
9
1.00
3
1.35
9
1.70
3

0.2 0.99
1.52
0.3
4
2.04
0.4
5
2.54
0.5
9
1.56
0.2
8
2.38
0.3
4

Develop branch y
and z
1) At x= 1

Z(1, 0.33)

2) At x= 1.5

Z(1.5, 0.33)

3) At x= 2

Z(2, 0.33)

70

Answer

# Calculate
by your own
since the
data give the
wrong
answer
71

# Calculate
by your own
since the
data give the
wrong
72
answer

EXERCISE 2

73

10

1.5

10

1.5

9.95

1.5

1.5

7.32
74

EXERCISE 3

75

List of youtubes
Thank You The Educated Race
Will People Follow The Crowd In An
Elevator Experiment
https://www.youtube.com/watch?v=MDD4IkVZWTM

76

You might also like