NumericalMethods G
NumericalMethods G
NumericalMethods G
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
or as ordered pairs
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
Existence: pn that satisfies (1) for the given data exists and the
formulas are given
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
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
x −x 1 x −x 0
L0 (x ) = x0 −x1 , L1 (x ) = x 1 −x 0
p1 (x ) = L0 (x )f0 + L1 (x )f1
x − x1 x − x0
= · f0 + · f1
x0 − x1 x1 − x0
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
Answer
ln 9.2 ≈ p1 (9.2) = 2.2188 and = 0.0004
Quadratic interpolation:
interpolation of given (x0 , f0 ), (x1 , f1 ), (x2 , f2 ) by a
second-degree polynomial p2 (x )
Lagrange’s idea
with:
L0 (x0 ) = 1, L1 (x1 ) = 1, L2 (x2 ) = 1
L0 (x1 ) = L0 (x2 ) = 0
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 )
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,
(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
Answer
ln 9.2 ≈ p2 (9.2)
= 0.54 · 2.1972 + 0.48 · 2.2513 − 0.02 · 2.3979
= 2.2192
where:
Lk (xk ) = 1
Lk = 0 at the other nodes
Lk = independent of the function f to be interpolated
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)
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
pn+1 (x ) − pn (x )
Newton’s form
practically more important for solving ODEs
involves fewer arithmetic operations
pn (x ) = pn−1 (x ) + gn (x )
and
gn (x ) = pn (x ) − pn−1 (x )
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
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
p1 (x ) = f0 + (x − x0 )f [x0 , x1 ]
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 )
at x = 9.2
approximate values :
p1 (9.2) = 2.220782
p2 (9.2) = 2.219238
p3 (9.2) = 2.219208
x0 , x1 = x0 + h , x2 = x0 + 2h , · · · , xn = x0 + nh
where h = distance
∆fj = fj +1 − fj
∆2 fj = ∆fj +1 − ∆fj
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
n !
X r
f (x ) ≈ pn (x ) = ∆s f0 , (10)
s
s =0
(x = x0 + rh , r = (x − x0 )/h )
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!
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
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
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
∇fj = fj − fj −1
∇2 f j = ∇f j − ∇ f j − 1
∇k fj = ∇k −1 fj − ∇k −1 fj −1 (k = 1, 2, · · · ) (12)
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.
Solution: Forward
r = (1.72 − 1.70)/0.1 = 0.2
j = 0 to 3
Solution: Backward
r = (1.72 − 2.00)/0.1 = −2.8