Engineering Math: Interpolation Guide
Engineering Math: Interpolation Guide
ENGINEERING MATHEMATICS 4
90
80
70
60
Engine power (HP)
50
40
30
20
10
0
0 200 400 600 800 1000 1200 1400 1600
90
80
70
60
Engine power (HP)
50
40
30
20
10
0
0 200 400 600 800 1000 1200 1400 1600
80
70
? 60
Engine power (HP)
50
40
30
20
10
0
0 200 400 600 800 1000 1200 1400 1600
You need
information
of the air pressure
at altitude 9.5 km
But
Data is not
Available ?
HOW to get
The air pressure
90
80
f ( x2)
? 70
60 f ( x1)
f ( x)
Engine power (HP)
50
40
30
20
10
x1 x x2
0
0 200 400 600 800 1000 1200 1400 1600
a ( x 2 − x 1 ) ( f ( x)− f ( x 1 ) )=( x− x 1 ) ( f ( x 2 )− f ( x 1 ) )
b ( x 2 − x 1 ) f ( x)−( x 2 − x1 ) f ( x 1 )=
( x− x 1 ) f ( x 2 )−( x− x 1 ) f ( x 1 )
( x 2 − x 1 ) f ( x)=
( x− x1 ) f ( x 2 )−( x− x 1 ) f ( x 1 )+ ( x 2− x 1 ) f ( x 1 )
( x 2 − x 1 ) f ( x)=( x− x 1 ) f ( x 2 )+ ( x 2 − x) f ( x 1 )
x1 x x2
( x 2 − x) ( x− x 1 )
f ( x)= f ( x1 )+ f ( x 2)
f ( x) ( x 2 − x1 ) ( x 2− x 1 )
f ( x1) ( x 2− x) f ( x 1 )+ ( x− x 1 ) f ( x 2 )
f ( x)=
( x2− x1)
x1 f ( x 1)
x1 x2 x2 f ( x2)
x
90
80
80 77
70
60 60
60 55
50 50
Engine power (HP)
50
40 40
40
30 30
30 25 25
20
20
10
0
0
0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600
(900−820)60+ (820−700) 77
Power= = 70.2
90
(900−700)
80
80 77
70
60 60
60 55
50 50
Engine power (HP)
50
40 40
40
30 30
30 25 25
20
20
10
0
0
0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600
You need
information
of the air pressure
at altitude 9.5 km
No problem,
Between 8-10
and dance
4
x 1 =8 f ( x 1 )=3.565 10
x=9.5 4 N
Pressure=2.8788 10 2
m
4
x 2 =10 f ( x 2 )=2.650 10
m-code function
function fx = IntpLinear(x,x1,fx1,x2,fx2)
% Linear interpolation 2 points
fx = ((x2-x)*fx1+(x-x1)*fx2)/(x2-x1);
70
60 60
60 55
50 50
Engine power (HP)
50
40 40
40
30 30
30 25 25
20
20
10
0
0
0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600
70
60 60
60 55
50 50
Engine power (HP)
50
40 40
40
30 30
30 25 25
20
20
10
0
0
0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600
70
60 60
60 55
50 50
Engine power (HP)
50
40 40
40
30 30
30 25 25
20
20
10
0
0
0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600
70
60 60
60 55
50 50
Engine power (HP)
50
40 40
40
30 30
30 25 25
20
20
10
0
0
0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600
90
80
80 77
70
60 60
60 55
50 50
Engine power (HP)
50
40 40
40
30 30
30 25 25
20
20
10
0
0
0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600
70
60 60
60 55
50 50
Engine power (HP)
50
40 40
40
30 30
30 25 25
20
20
10
0
0
0 100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600
f ( x 2)
Linear interpolation:
( x 2 − x) ( x− x 1 )
f ( x)= f ( x1 )+ f ( x 2)
f ( x) ( x 2 − x1 ) ( x 2− x 1 )
f ( x1)
Lagrange writes in different way:
( x− x 2 ) ( x− x 1 )
f ( x)= f ( x1 )+ f ( x 2)
( x1 − x 2 ) ( x 2− x 1 )
L1 ( x) L 2 ( x)
f ( x3)
f ( x2)
f ( x)
x1 x x2 x3
( x− x 2 )( x− x 3 ) ( x− x 1 )( x− x 3 ) ( x− x 1 )( x− x 2 )
f ( x)= f ( x 1 )+ f ( x 2 )+ f ( x3 )
( x1 − x 2 )( x 1− x 3 ) ( x 2 − x 1 )( x 2− x 3 ) ( x 3− x 1 )( x 3 − x 2 )
L1 ( x) L 2 ( x) L3 ( x)
f ( x4 )
Learning the pattern of Lagrange
2 and 3 points. Write the equation for
f ( x3) Lagrange 4 points !
f ( x 2)
f ( x) ( x− x 2 )( x− x 3 )( x− x 4 )
L1 ( x)=
( x 1 − x 2 )( x 1 − x 3 )( x 1− x 4 )
f ( x1)
( x− x 1 )( x− x 3 )( x− x 4 )
L 2 ( x)=
( x 2 − x 1 )( x 2 − x 3 )( x 2 − x 4 )
x1 x x2 x3 x4
( x− x 1 )( x− x 2 )( x− x 4 )
L3 ( x)=
( x 3 − x 1 )( x 3 − x 2 )( x 3 − x 4 )
( x− x 1 )( x− x 2 )( x− x 3 )
L 4 ( x)=
( x 4 − x 1 )( x 4 − x 2 )( x 4 − x 3 )
f ( x)= L 1 ( x) f ( x 1 )+ L 2 ( x) f ( x 2 )+ L3 ( x) f ( x 3 )+ L 4 ( x) f ( x 4 )
1
Predict the velocity when
the displacement 3 mm
0.5
by using Lagrange
velocity (m/s)
0
0 1 2 3 4 5 6 7 a) 2 points
b) 3 points
-0.5
c) 4 points
-1
Plot the functions and
-1.5
discuss your results
displacement (mm)
Use IntpLagrange.m to
x-value v-value
predict the velocity when
0 1
the displacement 3 mm
2 -1
4 -1.2
6 1
f ( x)= A+ c= f ( x 1 )+ c
f ( x)
From the simple triangular ratio (see page 9)
f ( x1) c
c=
( f ( x 2 )− f ( x 1 ))
( x− x ) 1
( x 2− x 1 )
f ( x)=a 0+ a1 ( x− x 1 )
f ( x)=a 0+ a1 ( x− x 1 )+ a 2 ( x− x 1 )( x− x 2 )
a 2 can be found for the additional data x 3 → f ( x 3 )=a 0 + a1 ( x 3− x 1 )+ a 2 ( x 3 − x 1 )( x 3 − x 2 )
f ( x 2 )− f ( x 1 )
f ( x 3 )− f ( x 1 )− ( x 3− x 1 )
f ( x 3 )−a0 −a1 ( x 3 − x 1 ) x 2− x 1
a 2= =
( x 3− x 1 )( x 3− x 2 ) ( x 3− x 1 )( x 3 − x 2 )
f ( x 2 )− f ( x 1 )
f ( x 3 )− f ( x 1 )− ( x 3− x 1 )
x 2− x 1
=
( x 3− x 1 )( x 3 − x 2 )
f ( x 3 )− f ( x 2 ) f ( x 2 )− f ( x 1 )
−
x 3− x 2 x 2 − x1
a 2=
( x3− x1)
x3 f ( x3)
f ( x)=a 0+ a1 ( x− x 1 )+ a 2 ( x− x 1 )( x− x 2 )
Available data
a) Prepare the Newton divided difference table
x y
b) Write the predicted equation
2.0 0.510
2.1 0.521 c) Predict the value y when x=2.5
2.4 0.510 d) Plot the predicted equations with
2.6 0.381 the available data
xx = 2.5
y(2.5) = 0.4633
y (2.5)=0.4633
or
or
f ( x)=a 0+ a1 ( x− x 1 )+ a 2 ( x− x 1 )( x− x 2 )
10
8
stress y
0
0 50 100 150 200 250 300 350
displacement x
10
8
stress y
0
0 50 100 150 200 250 300 350
displacement x
8
stress y
displacement x
Mathematicians,
they have developed a method to generate several
equations depending the range:
Piecewise Polynomial
Let's see how Piecewise Polynomial can help us
f ( x)
s n ( x)
s1 ( x) si ( x) fn
f n−1
f2
f 1+ 1
fi
f1
In cubic spline, each interval of the data is set with each unique polynomial.
This is called
f ( x) s 2 ( x) si+ 1 ( x)
Spline function
s n−1 ( x)
si ( x)
s1 ( x) fn
f n−1
f2
f 1+ 1
fi
f1
hk =( x k + 1− x k )
f k + 1− f k k =1,2,3 ⋯ , n−1
d k=
hk
i=1,2,3 ⋯ , n−1
mi + 1−mi
ai =
6 hi
mi
bi =
2
ci=
( hi )(
f i+ 1 − f i
−
2 hi mi + hi mi+ 1
6 )
d i= f i
x y
. .
. .
-1 -1
0 0
1 1
2 0
. .
. .
f k + 1− f k
hk =( x k + 1− x k ) d k = b k =6(d k + 1 −d k )
hk
-1 -1
1 1
0 0 0
1 1
1 1 -12
1 -1
2 0
hk mk + 2(hk + hk + 1 ) mk + 1 + hk + 1 m k + 2 = b k
m2 =0.8
m3=−3.2
0 -1
1 1 0.1333 0 0.8667 -1
0.8 0
2 1 -0.6667 0.4 1.2667 0
-3.2 1
3 1 0.5333 -1.6 0.0667 1
0 0
Since 1.5 is in the third interval, therefore use the third polynomial data
hk =( x k + 1− x k )
f k + 1− f k k =1,2,3 ⋯ , n−1
d k=
hk
i=1,2,3 ⋯ , n−1
mi + 1−mi
ai =
6 hi
mi
bi =
2
ci=
(
f i+ 1 − f i
hi
−
)(
2 hi mi + hi mi+ 1
6 )
d i= f i
x y y'
. .
. .
-1 -1 -1
0 0
1 1
2 0 1
. .
. .
f k + 1− f k
hk =( x k + 1− x k ) d k = b k =6(d k + 1 −d k )
hk
-1 -1
1 1
0 0 0
1 1
1 1 -12
1 -1
2 0
2 m1 + m2 = 12
m1 + 4 m2 + m3 = 0
Use any method for solving
m2 + 4 m3+ m4 = −12 simultaneous equations
m3+ 2 m4 = 12
m1 =6.1333
m2 =−0.2667
m3=−5.0667
m4 =8.5333
6.1333 -1
1 1
-0.2667 0
2 1
-5.0667 1
3 1 2.2667 -0.8444 -0.7333 1
8.5333 0
Since 1.5 is in the third interval, therefore use the third polynomial data
An experimental stress data along beam length is shown below (without unit).
The complete data at location x between 100 and 200 are documented in the table
12
10
8
stress y
0
0 50 100 150 200 250 300 350
displacement x
b) Plot the functions generated by the Lagrange method (3, 5 and 7 points) and the
Experimental data in the same plot