Documente Academic
Documente Profesional
Documente Cultură
4
INTERPOLATION
CHAPTER
CONTENT
• Polynomial
Interpola6on
• Lagrange
Interpola6on
• Newton-‐Divided
Difference
Method
• Likewise
Polynomial
Approxima6on
• Natural
Cubic
Splines
Polynomial
Interpolation
Approxima6ng
process
of
a
func6on
to
es6mate
the
missing
func6on
value
over
the
interval.
Polynomial
Interpola6on
Method
How it works?
f(x)
f(x)
What is the value of
f(xk)?
xn
x1
(xn, f(xn))
f(xk)
(x1, f(x1))
x0 x2
(x0, f(x0)) (x2, f(x2))
(x)
Linear interpolation (1st degree interpolation) Polynomial interpolation (2st degree interpolation & more)
f(x)
f(x)
(x0,f(x0)) (x2,f(x2))
(x1,f(x1))
(x1,f(x1))
(x0,f(x0))
x
x
L0 ( x ) f ( x0 )
L0 ( x ) f ( x0 ) L1 ( x ) f ( x1 ) L1 ( x ) f ( x1 ) L2 ( x ) f ( x2 )
P1 ( x ) =
x − x1
f ( x0 ) +
x − x0
f ( x1 ) P2 ( x ) =
( x − x1 ) ( x − x2 ) f x + (x − x0 )(x − x2 ) f x + (x − x0 )(x − x1 ) f x
( 0) ( 1) ( 2)
x0 − x1 x1 − x0 ( x0 − x1 ) ( x0 − x2 ) (x1 − x0 ) ( x1 − x2 ) (x2 − x0 )(x2 − x1 )
st nd rd
st nd Interpolation at 1 point Interpolation at 2 point Interpolation at 3 point
Interpolation at 1 point Interpolation at 2 point
Lagrange
Interpolation
Polynomial
• In
general,
Lagrange
Interpola6on
polynomial
is
given
by;
n
f ( x ) ≈ Pn ( x ) = ∑ Li ( x ) fi , Li ( x ) = ∏
n
(x − x ) j
i=0 j=0
j≠i
(x − x )
i j
LINEAR QUBIC
1st Order
3rd Order
P1 ( x ) = L0 (x) f0 + L1 (x) f1 P3 ( x ) = L0 (x) f0 + L1 (x) f1 + L2 (x) f2 + L3 (x) f3
QUARTIC
QUADRATIC
2nd Order 4rd Order
P2 ( x ) = L0 (x) f0 + L1 (x) f1 + L2 (x) f2 P4 ( x ) = L0 (x) f0 + L1 (x) f1 + L2 (x) f2 + L3 (x) f3 + L4 (x) f4
Lagrange
Interpolation
Polynomial
Example
4.1
1
• Given
the
following
data
which
is
generated
by
the
func6on
y =
x
x
1
2
3
4
5
y=f(x)
1
0.5
0.3333
0.25
0.2
• Approximate
f
(
4.5
)
by
using
linear,
quadra6c,
cubic
and
quar6c
Lagrange
interpola6on
method.
Find
the
absolute
error
for
each
approxima6on.
Lagrange
Interpolation
Polynomial
i
0
1
• Solu6ons;
f(4.5)=?
xi
4
5
x
1 2 3 4 x = 4.5
5
linear
1
Exact value of f (4.5) = = 0.2222
4.5
4.5 − 5 4.5 − 4
P1 ( 4.5) = 0.25 + 0.2
4−5 5− 4
P1 ( 4.5) = 0.125 + 0.1 = 0.225
ε a = Exact − Approximate
ε a = 0.2222 − 0.2250 = 0.0028
Lagrange
Interpolation
Polynomial
i
0
1
2
• Solu6ons;
xi
3
4
5
f(4.5)=?
Yi=fi
0.3333
0.25
0.2
Exact value of
1
f (4.5) =
4.5
= 0.2222 x
1 2 3 4 x = 4.5
5
Quadratic
P2 ( x ) =
( x − x1 ) ( x − x2 ) f x + ( x − x0 ) ( x − x2 ) f x + ( x − x0 ) ( x − x1 ) f x
( 0) ( 1) ( 2)
( x0 − x1 ) ( x0 − x2 ) ( x1 − x0 ) ( x1 − x2 ) ( x2 − x0 ) ( x2 − x1 )
P2 ( 4.5) =
( 4.5 − 4) ( 4.5 − 5) 0.3333+ ( 4.5 − 3) ( 4.5 − 5) 0.25 + ( 4.5 − 3) ( 4.5 − 4) 0.2
(3− 4) (3− 5) ( 4 − 3) ( 4 − 5) (5 − 3) (5 − 4)
P2 ( 4.5) = −0.0417 + 0.1875 + 0.0750 = 0.2208
ε a = Exact − Approximate
ε a = 0.2222 − 0.2208 = 0.0014
Lagrange
Interpolation
Polynomial
i
0
1
2
3
• Solu6ons;
xi
2
3
4
5
f(4.5)=?
Yi=fi
0.5
0.3333
0.25
0.2
Exact value of
f (4.5) =
1
= 0.2222 x
4.5 1 2 3 4 x = 4.5
5
Cubic
P3 ( x ) =
( x − x1 ) ( x − x2 ) ( x − x3 ) f x + ( x − x0 ) ( x − x2 ) ( x − x3 ) f x + ( x − x0 ) ( x − x1 ) ( x − x3 ) f x + ( x − x0 ) ( x − x1 ) ( x − x2 ) f x
( 0) ( 1) ( 2) ( 3)
( x0 − x1 ) ( x0 − x2 ) ( x0 − x3 ) ( x1 − x0 ) ( x1 − x2 ) ( x1 − x3 ) ( x2 − x0 ) ( x2 − x1 ) ( x2 − x3 ) ( x3 − x0 ) ( x3 − x1 ) ( x3 − x2 )
P2 ( 4.5) =
( 4.5 − 3) ( 4.5 − 4) ( 4.5 − 5) 0.5 + ( 4.5 − 2) ( 4.5 − 4) ( 4.5 − 5) 0.3333+ ( 4.5 − 2) ( 4.5 − 3) ( 4.5 − 5) 0.25 + ( 4.5 − 2) ( 4.5 − 3) ( 4.5 − 4) 0.2
(2 − 3) (2 − 4) (2 − 5) (3− 2) (3− 4) (3− 5) ( 4 − 2) ( 4 − 3) ( 4 − 5) (5 − 2) (5 − 3) (5 − 4)
P2 ( 4.5) = 0.0313− 0.1042 + 0.2344 + 0.0625 = 0.2240
ε a = Exact − Approximate
ε a = 0.2222 − 0.2240 = 0.0018
Lagrange
Interpolation
Polynomial
i
0
1
2
3
4
• Solu6ons;
xi
1
2
3
4
5
f(4.5)=?
Yi=fi
1
0.5
0.3333
0.25
0.2
Exact value of
f (4.5) =
1
= 0.2222 x
4.5 1 2 3 4 x = 4.5
5
Quartic
P4 ( x ) =
( x − x1 ) ( x − x2 ) ( x − x3 ) ( x − x4 ) f x + ( x − x0 ) ( x − x2 ) ( x − x3 ) ( x − x4 ) f x + ( x − x0 ) ( x − x1 ) ( x − x3 ) ( x − x4 ) f x + ( x − x0 ) ( x − x1 ) ( x − x2 ) ( x − x4 ) f x + ( x − x0 ) ( x − x1 ) ( x − x2 ) ( x − x3 ) f x
( 0) ( 1) ( 2) ( 3) ( 4)
( x0 − x1 ) ( x0 − x2 ) ( x0 − x3 ) ( x0 − x4 ) ( x1 − x0 ) ( x1 − x2 ) ( x1 − x3 ) ( x1 − x4 ) ( x2 − x0 ) ( x2 − x1 ) ( x2 − x3 ) ( x2 − x4 ) ( x3 − x0 ) ( x3 − x1 ) ( x3 − x2 ) ( x3 − x4 ) ( x4 − x0 ) ( x4 − x1 ) ( x4 − x2 ) ( x4 − x3 )
P4 ( 4.5) =
( 4.5− 2) ( 4.5− 3) ( 4.5− 4) ( 4.5− 5) 1+ ( 4.5−1) ( 4.5− 3) ( 4.5− 4) ( 4.5− 5) 0.5+ ( 4.5−1) ( 4.5− 2) ( 4.5− 4) ( 4.5− 5) 0.3333+ ( 4.5−1) ( 4.5− 2) ( 4.5− 3) ( 4.5− 5) 0.25+ ( 4.5−1) ( 4.5− 2) ( 4.5− 3) ( 4.5− 4) 0.2
(1− 2) (1− 3) (1− 4) (1− 5) (2 −1) (2 − 3) (2 − 4) (2 − 5) (3−1) (3− 2) (3− 4) (3− 5) ( 4 −1) ( 4 − 2) ( 4 − 3) ( 4 − 5) (5−1) (5− 2) (5− 3) (5− 4)
ε a = Exact − Approximate
ε a = 0.2222 − 0.2161 = 0.0061
Exercise
• Try
This!
Exercise
4
(Ques6on
7)
The
following
table
gives
certain
corresponding
values
of
x
and
log10
x.
Using
Lagrange
interpola6on,
compute
the
following
term,
if
possible.
(a) log10(323.5)
(b) Log10(353.5)
1 X1 f1 [0] f1 [1]=( f2 [0]-‐f1 [0])/(X2-‐X1) f1 [2]=( f2 [1]-‐f1 [1])/(X3-‐X1) f1 [3] =f2 [2]-‐f1 [2] /(X4-‐X1)
4 X4 f4 [0]
• and
hence;
f (x) ≈ P4 (x) = f0[ ] + f0[ ] ( x − x0 ) + f0[
2]
0 1
( x − x0 ) ( x − x1 ) + f0[3] ( x − x0 ) ( x − x1 ) ( x − x2 ) + f0[4] ( x − x0 ) ( x − x1 ) ( x − x2 ) ( x − x3 )
Newton
Divided
Difference
(NDD)
Polynomial
• Example
Given
;
x
2.1
2.4
2.6
f(x)
0.521
0.510
0.381
1) Find
the
NDDP
interpola6on
and
approxima6on
value
for
f(2.5).
Solu6ons;
i
xi
fi
[0]
fi
[1]
fi
[2]
0
2.1
f0
[0]=a0=0.521
f0
[1]=(
f1
[0]-‐f0
[0])/(X1-‐X0)
f0
[2]
=(
f1
[1]-‐f0
[1])/(X2-‐X0)
=
(0.510-‐0.521)/(2.4-‐2.1)
=((-‐0.037)-‐(-‐0.645))/(2.6-‐2.1)
=-‐0.037
=-‐1.216
1
2.4
0.510
f1
[1]=(
f2
[0]-‐f1
[0])/(X2-‐X1)
=(0.381-‐0.510)/(2.6-‐2.4)
=-‐0.645
2
2.6
0.381
Given
f(x)=e-‐x.
(a) Complete
the
following
table
x
0
0.25
0.75
1.0
f(x)=e-‐x
(b) Hence,
find
P3(0.4)
by
using
NDD
Polynomial
method.
(c) If
(0.5,
0.6065)
is
added
into
the
above
data
set,
find
f(0.4)
by
using
NDDP
method.
To
be
con6nued
ai
bi
ci
di
mi+1
− mi mi f ( xi+1 ) − f ( xi ) " 2hi mi + hi mi+1 % f (xi )
−$ '
6hi
2 hi # 6 &
k
xk
fk
hk
dk
bk
S2
1
S1 0
-‐1
-‐1
h0=0-‐(-‐1)
d0=(0-‐(-‐1))/1
b0=6(1-‐1)
x =1
=1
=0
-1 S0 1 2
-1 1
0
0
h1=1-‐0
d1=(1-‐0))/1
b1=6(-‐1-‐1)
=1
=1
=6(-‐2)
=-‐12
2
1
1
h2=2-‐1
d2=(0-‐1))/1
=1
=-‐1
x0 x1 x2 x3 3
2
0
STEP 2 For natural cubic splines, slope of graph at 1st point (m0) and
final point must (mn) = 0.
Derive the system of linear equations using unknowns mk for
k=0,1,2,…,n-2 points. (continued in next page)
PIECEWISE
POLYNOMIAL
APPROXIMATION
(NATURAL
CUBIC
SPLINES)
STEP 2-cont’d General formula;
hk mk + 2 ( hk + hk+1 ) mk+1 + hk+1mk+2 = bk substitute k=0, 1, 2,…, n-2
1 m1=?
h1m1 + 2 ( h1 + h2 ) m2 + h2 m3 = b1
m2=?
m3=0
(end
point,
n-‐2)
1m1 + 2 (1+1) m2 +1(0) = −12
Stop k at n-2= (3-2)=1
m1 + 4m2 = −12…(ii)
STEP 3 Solve the system of linear equations using one of previously learned methods
! 4 1 $! m1 $ ! 0 $ )1, " 4 1 0 &
# &# &=# & → − + . R1 + R2 → R2 ⇒$ ( Using backward substitution,
" 1 4 %#" m2 &% " −12 % *4- $# 0 15
4 −12 ' calculate the value of m2 and m1
Hence, m2 = -16/5
m1= 4/5
PIECEWISE
POLYNOMIAL
APPROXIMATION
(NATURAL
CUBIC
SPLINES)
STEP 4 General spline formula: sk (x) = mk ( xk+1 − x )3 + mk+1 ( x − xk )3 + "$ fk − mk hk %' ( xk+1 − x ) + "$ fk+1 − mk+1 hk %' ( x − xk )
6hk 6hk # hk 6 & # hk 6 &
wherek = 0,1, 2, 3,...n −1.
at k = 0
k = 1, 2, 3…,n-1 m0 3 m 3 "f m % "f m %
s0 (x) = ( x1 − x ) + 1 ( x − x0 ) + $ 0 − 0 h0 ' ( x1 − x ) + $ 1 − 1 h0 ' ( x − x0 )
6h0 6h0 # h0 6 & # h0 6 &
S2 0 4 " −1 0 % "0 4 %
1 s0 (x) =
3 3
( 0 − x ) + 5 ( x − (−1)) + $# − (1)'& ( 0 − x ) + $# − 5 (1)'& ( x − (−1))
S1 6(1) 6(1) 1 6 1 6
x
-1 S0 1 2 2 2
s0 (x) = (x +1)3 + x − (x +1) ⇒ x ∈ [−1, 0 ]
-1 15 15
at k = 1
m 3 m 3 "f m % "f m %
s1 (x) = 1 ( x2 − x ) + 2 ( x − x1 ) + $ 1 − 1 h1 ' ( x2 − x ) + $ 2 − 2 h1 ' ( x − x1 )
6h1 6h1 # h1 6 & # h1 6 &
4 − 1653 3 "0 4 % " 1 − 16 %
s1 (x) = 5
(1− x ) ( x − 0) + $# − 5 (1)'& (1− x ) + $# − 5 (1)'& ( x − 0)
+
6(1) 6(1) 1 6 1 6
2 8 2 23
s1 (x) = (1+ x)3 − x 3 − (1− x) + x ⇒ x ∈ [ 0,1]
15 15 15 15
at k = 2
m2 3 m 3 "f m % "f m %
s2 (x) = ( x3 − x ) + 3 ( x − x2 ) + $ 2 − 2 h2 ' ( x3 − x ) + $ 3 − 3 h2 ' ( x − x2 )
6h2 6h2 # h2 6 & # h2 6 &
− 165 3 0 3 " 1 − 16 % "0 0 %
s2 (x) = (2 − x ) + ( x −1) + $# − 5 (1)'& ( 2 − x ) + $# − (1)'& ( x −1)
6(1) 6(1) 1 6 1 6
8 23
s2 (x) = − (2 − x)3 + (2 − x) ⇒ x ∈ [1, 2 ]
15 15
PIECEWISE
POLYNOMIAL
APPROXIMATION
(NATURAL
CUBIC
SPLINES)
ALTERNATIVE FOR STEP 4
ai
bi
ci
di
mi+1
− mi mi f ( xi+1 ) − f ( xi ) " 2hi mi + hi mi+1 % f (xi )
−$ '
6hi
2 hi # 6 &
m1 45 2 d1 = f (x1 ) = 0
b1 = = =
2 2 5 d2 = f (x2 ) = 1
m2 − 165 8
b2 = = =−
2 2 5
PIECEWISE
POLYNOMIAL
APPROXIMATION
(NATURAL
CUBIC
SPLINES)
Spline Equations;
3 2 8 3 2 8
S0 ( x ) = a0 ( x − x0 ) + b0 ( x − x0 ) + c0 ( x − x0 ) + d0 = ( x − (−1)) + 0 ( x − (−1)) + ( x − (−1)) + (−1)
15 15
2 3 13
S0 ( x ) = ( x +1) + ( x +1) −1
15 15
3 2 2 3 2 2 4
S1 ( x ) = a1 ( x − x1 ) + b1 ( x − x1 ) + c1 ( x − x1 ) + d1 = ( x − (0)) + ( x − 0) +1 ( x − (0)) + 0
3 5 15
2 3 2 2 4
S1 ( x ) = − ( x ) + ( x ) +1 x
3 5 15
3 2 8 3 8 2 1
S2 ( x ) = a2 ( x − x2 ) + b2 ( x − x2 ) + c2 ( x − x2 ) + d2 = ( x −1) − ( x −1) + ( x −1) +1
15 5 15
PIECEWISE
POLYNOMIAL
APPROXIMATION
(NATURAL
CUBIC
SPLINES)
• Try This!