You are on page 1of 39

Numerics in General: Interpolation

Interpolation
Given: values of f (x ) at different points x0 , x1 , · · · , xn
Unknown: approximate values of f (x ) for “new” x’s that lie
between the given or known points

the given values can be written as

f0 = f (x0 ), f1 = f (x1 ), · · · , fn = f (xn )

or as ordered pairs

(x0 , f0 ), (x1 , f1 ), · · · , (xn , fn )

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation
these given function values may come from:
mathematical functions
“empirical” functions
standard idea in interpolation
find a pn (x ) of degree n (or less) that assumes the given values,
thus:
pn (x0 ) = f0 , pn (x1 ) = f1 , · · · , pn (xn ) = fn (1)

where:
x0 , · · · , xn = nodes
pn
interpolation polynomial
called as approximation or polynomial approximation of f if f (x )
is a mathematical function
used to determine (approximate) f for x’s between x0 and xn
(interpolation) or outside the interval x0 5 x 5 xn
(extrapolation)
Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods
Numerics in General: Interpolation

Weierstrass aproximation theorem


|f (x ) − pn (x )| < β, ∀x on J
where:
continuous: f (x )
interval: J : a 5 x 5 b
error bound: β > 0
polynomial of sufficiently high degree n: pn (x )

Existence: pn that satisfies (1) for the given data exists and the
formulas are given

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

Uniqueness: pn is unique
if another polynomial qn satisfies:

qn (x0 ) = f0 , · · · , qn (xn ) = fn

then pn (x ) − qn (x ) = 0 at x0 , · · · , xn
polynomial pn − qn of degree n (or less) with n + 1 roots must
be identically zero, thus pn (x ) = qn (x ), ∀x
Determining pn :
Lagrange interpolation
Newton’s divided difference interpolation
Newton’s backward difference interpolation

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

Given: (x0 , f0 ), (x1 , f1 ), · · · , (xn , fn ), with arbitrarily spaced xj

Lagrange’s idea
multiply each fj with a polynomial that is 1 at xj and 0 at the
other n nodes
add these n + 1 polynomials

Simplest Case: Linear interpolation


interpolation by straight line through (x0 , f0 ), (x1 , f1 )
if L0 is a linear polynomial that is 1 at x0 and 0 at x1
similarly, L1 is 0 at x0 and 1 at x1
thus: p1 = L0 f0 + L1 f1

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

Figure : Linear Interpolation.

x −x 1 x −x 0
L0 (x ) = x0 −x1 , L1 (x ) = x 1 −x 0

linear Lagrange polynomial

p1 (x ) = L0 (x )f0 + L1 (x )f1
x − x1 x − x0
= · f0 + · f1
x0 − x1 x1 − x0

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

Example: Lagrange Interpolation


Compute a 4D-value of ln 9.2 from ln 9.0 = 2.1972,
ln 9.5 = 2.2513 by linear Lagrange interpolation and
determine the error using ln 9.2 = 2.2192 (4D)

Solution:
x0 = 9.0, f0 = ln 9.0
x1 = 9.5, f1 = ln 9.5
L0 (9.2) = 0.6
L1 (9.2) = 0.4

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

Example: Lagrange Interpolation

Answer
ln 9.2 ≈ p1 (9.2) = 2.2188 and  = 0.0004

not sufficient for 4D accuracy

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

Quadratic interpolation:
interpolation of given (x0 , f0 ), (x1 , f1 ), (x2 , f2 ) by a
second-degree polynomial p2 (x )

Lagrange’s idea

p2 (x ) = L0 (x )f0 + L1 (x )f1 + L2 (x )f2 (2)

with:
L0 (x0 ) = 1, L1 (x1 ) = 1, L2 (x2 ) = 1
L0 (x1 ) = L0 (x2 ) = 0

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

l0 (x ) (x − x1 )(x − x2 )
L0 (x ) = =
l0 (x0 ) (x0 − x1 )(x0 − x2 )
l1 (x ) (x − x0 )(x − x2 )
L1 (x ) = =
l1 (x1 ) (x1 − x0 )(x1 − x2 )
l2 (x ) (x − x0 )(x − x1 )
L2 (x ) = = .
l2 (x2 ) (x2 − x0 )(x2 − x1 )

numerator: Lk (xj ) = 0 if j , k
denominator: Lk (xk ) = 1 (equals the numerator at x = xk )

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

Example: Quadratic Lagrange Interpolation


Compute ln 9.2 using the data in the previous example
with an additional value ln 11.0 = 2.3979

Solution:
(x − 9.5)(x − 11.0)
L0 (x ) =
(9.0 − 9.5)(9.0 − 11.0)
= x 2 − 20.5x + 104.5,
L0 (9.2) = 0.54,

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

Example: Quadratic Lagrange Interpolation

(x − 9.0)(x − 11.0)
L1 (x ) =
(9.5 − 9.0)(9.5 − 11.0)
1
= − (x 2 − 20x + 99),
0.75
L1 (9.2) = 0.48,

(x − 9.0)(x − 9.5)
L2 (x ) =
(11.0 − 9.0)(11.0 − 9.5)
1 2
(x − 18.5x + 85.5),
=
3
L2 (9.2) = −0.02

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

Example: Quadratic Lagrange Interpolation

Answer

ln 9.2 ≈ p2 (9.2)
= 0.54 · 2.1972 + 0.48 · 2.2513 − 0.02 · 2.3979
= 2.2192

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

General Lagrange Interpolation Polynomial


n
X
f (x ) ≈ pn (x ) = Lk (x )fk (3)
k =0
n
X lk (x )
= fk
lk (xk )
k =0

where:
Lk (xk ) = 1
Lk = 0 at the other nodes
Lk = independent of the function f to be interpolated

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

l0 (x ) = (x − x1 )(x − x2 ) · · · (x − xn )
lk (x ) = (x − x0 ) · · · (x − xk −1 )(x − xk +1 ) · · · (x − xn )
ln (x ) = (x − x0 )(x − x1 ) · · · (x − xn−1 )

0<k <n
pn (xk ) = fk
lk (xj ) = 0 if j , k
so that: x = xk and
lk (xk )
fk = fk
lk (xk )
Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods
Numerics in General: Interpolation

Error Estimate:

n (x ) = f (x ) − pn (x ) (4)
f (n+1) (t )
= (x − x0 )(x − x1 ) · · · (x − xn )
(n + 1)!
where:
f (n+1) exists and is continuous
t between x0 and xn (or between x0 , xn and x)

choose nodes on both sides of x

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

Example:
Estimate the error in the first example using the
interpolation error formula and error principle.

Solution:
Exact: ln 9.2 = 2.2192 (4D)
Approximate: p1 (9.2) = 2.2188
Interpolation Error:

f 2 (t )
1 (x ) = (x − x0 )(x − x1 )
2!
where:
x0 = 9.0
x1 = 9.5
f (t ) = ln t, f 0 (t ) = t −1 , f 00 (t ) = −t −2
Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods
Numerics in General: Interpolation

thus:
1 (9.2) = 0.03t −2

t = 9: maximum 1 (9.2) = 0.00037


t = 9.5: minimum 1 (9.2) = 0.00033
and: 0.00033 5 1 (9.2) 5 0.00037
the error 0.0004 disagrees with the result above

using 5D computation: f0 = 2.19722 and f1 = 2.25129


p1 (9.2) = 2.21885
 = 0.00035 between the range!

discrepancy (0.0004 vs 0.00035) is caused by rounding

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Numerics in General: Interpolation

Error Principle: error estimate of pn (x )

pn+1 (x ) − pn (x )

with 4D: p2 (9.2) − p1 (9.2) = 2.2192 − 2.2188 = 0.0004

with 5D: p2 (9.2) = 2.21916

p2 (9.2) − p1 (9.2) = 2.21916 − 2.21885 = 0.00031

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Divided Difference

Newton’s form
practically more important for solving ODEs
involves fewer arithmetic operations

let pn−1 (x ) be the (n − 1)st Newton polynomial


thus:
pn−1 (x0 ) = f0 ,
pn−1 (x1 ) = f1 , · · · ,
pn−1 (xn−1 ) = fn−1
the nth Newton polynomial

pn (x ) = pn−1 (x ) + gn (x )

and
gn (x ) = pn (x ) − pn−1 (x )

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Divided Difference

gn (x ) = an (x − x0 )(x − x1 ) · · · (x − xn−1 )
to determine an :
set x = xn and pn (xn ) = fn
solve for an
fn − pn−1 (xn )
an = (5)
(xn − x0 )(xn − x1 ) · · · (xn − xn−1 )
k th divided difference:
f1 − f0
a1 = f [x0 , x1 ] =
x1 − x0

f [x1 , x2 ] − f [x0 , x1 ]
a2 = f [x0 , x1 , x2 ] =
x2 − x0

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Divided Difference

k th divided difference
f [x1 , · · · , xk ] − f [x0 , · · · , xk −1 ]
ak = f [x0 , · · · , xk ] = (6)
xk − x0

if n = 1:
f1 − p0 (x1 ) f1 − f0
a1 = = = f [ x0 , x1 ]
x1 − x0 x1 − x0

Newton interpolation polynomial of the first degree:

p1 (x ) = f0 + (x − x0 )f [x0 , x1 ]

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Divided Difference

if n = 2:
f2 − p1 (x2 ) f2 − f0 − (x2 − x0 )f [x0 , x1 ]
a2 = = = f [ x0 , x1 , x2 ]
(x2 − x0 )(x2 − x1 ) (x2 − x0 )(x2 − x1 )

second Newton polynomial

p2 (x ) = f0 + (x − x0 )f [x0 , x1 ] + (x − x0 )(x − x1 )f [x0 , x1 , x2 ]

Newton’s Divided Difference Interpolation Formula

f (x ) ≈ f0 + (x − x0 )f [x0 , x1 ] + (x − x0 )(x − x1 )f [x0 , x1 , x2 ] (7)


+ · · · + (x − x0 )(x − x1 ) · · · (x − xn−1 )f [x0 , · · · , xn ]

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Divided Difference
ALGORITHM INTERPOL (x0 , · · · , xn ; f0 , · · · , fn ; x̂)
This algorithm computes an approximation pn (x̂ ) of f (x̂ ) at x̂.
INPUT: Data (x0 , f0 ), (x1 , f1 ), · · · , (xn , fn ); x̂
OUTPUT: Approximation pn (x̂ ) of f (x̂ )
Set f [xj ] = fj (j = 0, · · · , n)
For m = 1, · · · , n − 1 do
For j = 0, · · · , n − m do
f [xj +1 , · · · , xj +m ] − f [xj , · · · , xj +m−1 ]
f [xj , · · · , xj +m ] =
xj +m − xj
End
End
Set p0 (x ) = f0
For k = 1, · · · , n do
pk (x̂ ) = pk −1 (x̂ ) + (x̂ − x0 ) · · · (x̂ − xk −1 )f [x0 , · · · , xk ]
End
OUTPUT pn (x̂ )
End INTERPOL
Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods
Interpolation: Newton’s Divided Difference
Example: Compute f (9.2) from the values shown in the
difference table:

xj fj = f (xj ) f [xj , xj +1 ] f [xj , xj +1 , xj +2 ] f [xj , · · · , xj +3 ]


8.0 2.079442
0.117783
9.0 2.197225 −0.006433
0.108134 0.000411
9.5 2.251292 −0.005200
0.097735
11.0 2.397895

f (x ) ≈ p3 (x ) = 2.079442 + 0.117783(x − 8.0)


−0.006433(x − 8.0)(x − 9.0)
+0.000411(x − 8.0)(x − 9.0)(x − 9.5)

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Divided Difference

at x = 9.2

exact value to 6D: f (9.2) = ln 9.2 = 2.219203

approximate values :

p1 (9.2) = 2.220782
p2 (9.2) = 2.219238
p3 (9.2) = 2.219208

accuracy increases as the order increases

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Forward Difference

in many applications xj ’s are regularly spaced:

x0 , x1 = x0 + h , x2 = x0 + 2h , · · · , xn = x0 + nh

where h = distance

first forward difference of f at xj :

∆fj = fj +1 − fj

second forward difference of f at xj :

∆2 fj = ∆fj +1 − ∆fj

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Forward Difference

k th forward difference

∆k fj = ∆k −1 fj +1 − ∆k −1 fj (k = 1, 2, · · · ) (8)
if we have a regular spacing:

∆k f0
f [x0 , · · · , xk ] = (9)
k !h k

Newton’s Forward Difference Interpolation Formula

n !
X r
f (x ) ≈ pn (x ) = ∆s f0 , (10)
s
s =0
(x = x0 + rh , r = (x − x0 )/h )

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Forward Difference

where:
! !
r r r (r −1)(r −2)···(r −s +1)
= 1, = s! (s > 0, integer)
0 s

in expanded form:

r (r − 1) 2
f (x ) = f0 + r ∆f0 + ∆ f0 + · · ·
2!
r (r − 1) · · · (r − n + 1) n
+ ∆ f0
n!

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Forward Difference

Error

n (x ) = f (x ) − pn (x ) (11)
n +1
h
= r (r − 1) · · · (r − n)f (n+1) (t )
(n + 1)!
consider:
∆n+1 f (t ) |r (r −1)···(r −n)|
f n+1 (t ) ≈ h n+1
, 1·2···(n+1)
5 1 if |r | 5 1
choose x0 , · · · , xn such that x is as well
centered between x0 , · · · , xn as possible

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Forward Difference

Example:
Compute cosh 0.56 using the forward difference interpolation
formula and the four values in the table below

j xj fj = cosh xj ∆fj ∆2 fj ∆3 fj
0 0.5 1.127626
0.057839
1 0.6 1.185465 0.011865
0.069704 0.000697
2 0.7 1.255169 0.012562
0.082266
3 0.8 1.337435

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Forward Difference

Solution:
0.6(−0.4)
cosh 0.56 ≈ 1.127626 + 0.6 · 0.057839 + · 0.011865
2
0.6(−0.4)(−1.4)
+ · 0.000697
6
= 1.160944

Error estimate:

0.14
3 (0.56) = · 0.6(−0.4)(−1.4)(−2.4) cosh t
4!
= A cosh t

where:
A = −0.00000336
0.5 5 t 5 0.8

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Forward Difference

using the given interval:

A cosh 0.8 5 3 (0.56) 5 A cosh 0.5

the resulting estimation:

p3 (0.56) + A cosh 0.8 5 cosh 0.56 5 p3 (0.56) + A cosh 0.5

exact 6D-value: cosh 0.56 = 1.160941


numerical estimates: 1.160939 5 cosh 0.56 5 1.160941

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Backward Difference

Differences with the Forward Difference


employs backward-sloping differences
has the same difference table except for the
subscripts
first backward difference of f at xj

∇fj = fj − fj −1

second backward difference of f at xj

∇2 f j = ∇f j − ∇ f j − 1

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Backward Difference
k th backward difference

∇k fj = ∇k −1 fj − ∇k −1 fj −1 (k = 1, 2, · · · ) (12)

using the backward differences:


Newton’s backward difference interpolation formula

n !
X r +s−1
f (x ) ≈ pn (x ) = ∇s f0 (13)
s
s =0
(x = x0 + rh , r = (x − x0 )/h )

in expanded form:
r (r + 1 ) 2
f (x ) = f0 + r ∇f0 + ∇ f0 + · · ·
2!
r (r + 1) · · · (r + n − 1) n
+ ∇ f0
n!
Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods
Interpolation: Newton’s Backward Difference

Example:
Compute a 7D-value of the Bessel function J0 (x ) for x = 1.72
from the four values in the table below, using the forward and
backward formulas.

jfor jback xj J0 (xj ) 1st Diff 2nd Diff 3rd Diff


0 −3 1.7 0.3979849
−0.0579985
1 −2 1.8 0.3399864 −0.0001693
−0.0581678 0.0004093
2 −1 1.9 0.2818186 0.0002400
−0.0579278
3 0 2.0 0.2238908

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Backward Difference

Solution: Forward
r = (1.72 − 1.70)/0.1 = 0.2
j = 0 to 3

J0 (1.72) ≈ 0.3979849 + 0.2(−0.0579985)


0.2(−0.8)
+ · (−0.0001693)
2
0.2(−0.8)(−1.8)
+ · 0.0004093
6
= 0.3864183

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Interpolation: Newton’s Backward Difference

Solution: Backward
r = (1.72 − 2.00)/0.1 = −2.8

J0 (1.72) ≈ 0.2238908 − 2.8(−0.0579278)


−2.8(−1.8)
+ · (0.0002400)
2
−2.8(−1.8)(−0.8)
+ · 0.0004093
6
= 0.3864184

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods


Next: Final Exam

Engr. Rachel Mabanag Chong, PhD CITU–ECE416: Numerical Methods

You might also like