MA128 ALecture Week 5
MA128 ALecture Week 5
P(x) = a0 + a1 (x − z0 ) + a2 (x − z0 )(x − z1 ) +
· · · + am (x − z0 )(x − z1 ) · · · (x − zm−1 ),
with P(z0 ) = f (z0 ), P(z1 ) = f (z1 ), · · · , P(zm ) = f (zm ).
I where
aj = f [z0 , z1 , · · · , zj ], for j = 0, 1, · · · , m.
Newton Divided Difference Table
zi f [zi ] f [zi−1 , zi ] f [zi−2 , zi−1 , zi ] ··· f [z0 , z1 , · · · , zm ]
z0 f[z0 ] = a0
f[z0 , z1 ] = a1
z1 f [z1 ] f[z0 , z1 , z2 ] = a2
f [z1 , z2 ]
z2 f [z2 ] f [z1 , z2 , z3 ]
f [z2 , z3 ]
z3 f [z3 ] f [z2 , z3 , z4 ]
f [z3 , z4 ]
z4 f [z4 ] f [z3 , z4 , z5 ] ··· f[z0 , z1 , · · · , zm ] = am
f [z4 , z5 ]
z5 f [z5 ] f [z4 , z5 , z6 ]
f [z5 , z6 ]
z6 f [z6 ] f [z5 , z6 , z7 ]
f [z6 , z7 ]
z7 f [z7 ] f [z6 , z7 , z8 ]
f [z7 , z8 ]
z8 f [z8 ]
Double nodes, m = 2n + 1, xj = zbj/2c , f [xj , xj ] = f 0 (xj )
xi f [xi ] f [zi−1 , zi ] f [zi−2 , zi−1 , zi ] ··· f [z0 , z1 , · · · , zm ]
x0 f[x0 ] = a0
f[x0 , x0 ] = a1
x0 f [x0 ] f[x0 , x0 , x1 ] = a2
f [x0 , x1 ]
x1 f [x1 ] f [x0 , x1 , x1 ]
f [x1 , x1 ]
x1 f [x1 ] f [x1 , x1 , x2 ]
f [x1 , x2 ]
x2 f [x2 ] f [x1 , x2 , x2 ] ··· f[x0 , x0 , · · · , xn , xn ]
f [x2 , x2 ]
x2 f [x2 ] f [x2 , x2 , x3 ]
f [x2 , x3 ]
x3 f [x3 ] f [x2 , x3 , x3 ]
f [x3 , x3 ]
x3 f [x3 ]
Hermite Interpolation
(x0 , f (x0 ), f 0 (x0 )), (x1 , f (x1 ), f 0 (x1 )), · · · , (xn , f (xn ), f 0 (xn )),
(x0 , f (x0 ), f 0 (x0 )), (x1 , f (x1 ), f 0 (x1 )), · · · , (xn , f (xn ), f 0 (xn )),
H(x) = a0 + a1 (x − x0 ) + a2 (x − x0 )2 +
· · · + a2n+1 (x − x0 )2 (x − x1 )2 · · · (x − xn−1 )2 (x − xn ).
aj = f [z0 , z1 , · · · , zj ], for j = 0, 1, · · · , 2n + 1,
1.5
0.5
−0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
−15.7
10
−15.8
10
−15.9
10
−2
10
−4
10
−6
10
−8
10
−10
10
−12
10
0 5 10 15 20 25
1
Hermite Interpolation on 0.2+x 2 on [−1, 1]
Hermite Interpolation (red) vs. exact function (blue) for 1/(0.2+x2) on [−1, 1], 21 points
5
0
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
−5
10
−10
10
−15
10
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
Coefficients aj for Hermite Interpolation
Divided Difference Coefficients, semilog scale
8
10
7
10
6
10
5
10
4
10
3
10
2
10
1
10
0
10
−1
10
0 5 10 15 20 25 30 35 40 45
Hermite Interpolation
(x0 , f (x0 ), f 0 (x0 )), (x1 , f (x1 ), f 0 (x1 )), · · · , (xn , f (xn ), f 0 (xn )),
(x0 , f (x0 ), f 0 (x0 )), (x1 , f (x1 ), f 0 (x1 )), · · · , (xn , f (xn ), f 0 (xn )),
where
Hj (x) = 1 − 2(x − xj )L0j (xj ) L2j (x), Hbj (x) = (x − xj )L2j (x),
Q x − xi
with Lj (x) = i6=j .
xj − xi
(Equivalent) Hermite Interpolation Solution
(x0 , f (x0 ), f 0 (x0 )), (x1 , f (x1 ), f 0 (x1 )), · · · , (xn , f (xn ), f 0 (xn )),
where
Hj (x) = 1 − 2(x − xj )L0j (xj ) L2j (x), Hbj (x) = (x − xj )L2j (x),
Q x − xi
with Lj (x) = i6=j .
xj − xi
(Equivalent) Hermite Interpolation Solution
I Interpolating polynomial H(x) is
n
X n
X
H(x) = f (xj ) Hj (x) + f 0 (xj ) Hbj (x),
j=0 j=0
where
Hj (x) = 1 − 2(x − xj )L0j (xj ) L2j (x), Hbj (x) = (x − xj )L2j (x).
I For i 6= j,
I For i = j,
f (2n+2) (ξ(x))
f (x) = H(x) + (x − x0 )2 (x − x1 )2 · · · (x − xn )2 ,
(2n + 2)!
def (t − x0 )2 (t − x1 )2 · · · (t − xn )2
g (t) = (f (t) − H(t)) − (f (x) − H(x))
(x − x0 )2 (x − x1 )2 · · · (x − xn )2
n
Y (t − xj )2
= (f (t) − H(t)) − (f (x) − H(x)) ∈ C 2n+2 [a, b].
(x − xj )2
j=0
g 0 (xk ) = 0, , for k = 0, 1, · · · , n.
g (2n+2) (ξ) = 0.
Hermite Interpolation Error: Proof
Since
n
Y (t − xj )2 (2n+2)
g (2n+2) (ξ) = (f (t) − H(t))(2n+2) |t=ξ − (f (x) − H(x))( ) |ξ
(x − xj )2
j=0
(2n + 2)!
= f (2n+2) (ξ) − (f (x) − H(x)) Qn 2
j=0 (x − xj )
=0
Therefore
f (2n+2) (ξ(x))
f (x) = H(x) + (x − x0 )2 (x − x1 )2 · · · (x − xn )2 ,
(2n + 2)!
The Splines Idea
def
S(x) = Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3 .
I S(xj ) = f (xj ) j = 0, 1, · · · , n.
(S(x) matches f (x) at all nodal points)
I S(x) ∈ C 2 [x0 , xn ].
(S(x) remains smooth-enough)
Carl de Boor: The book about Splines
Carl de Boor
The Splines Idea
I Spine Interpolant S(x) for given n + 1 distinct points
(x0 , f (x0 )), (x1 , f (x1 )), · · · , (xn , f (xn )),
The Splines Equations (I)
For x ∈ [xj , xj+1 ], j = 0, 1, · · · , n − 1,
def
S(x) = Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3 .
I for j = 0, 1, · · · , n − 1,
aj = Sj (xj ) = f (xj ).
aj+1 − aj
bj + cj hj + dj hj2 = , j = 0, 1, · · · , n − 1.
hj
This ensures S(x) ∈ C [x0 , xn ].
The Splines Equations (II)
Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3
Sj0 (x) = bj + 2cj (x − xj ) + 3dj (x − xj )2
I 0
Define bn = Sn−1 (xn ); for j = 0, · · · , n − 1,
0
bj+1 = Sj+1 (xj+1 ) = Sj0 (xj+1 ) = bj + 2cj hj + 3dj hj2 .
Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3
Sj00 (x) = 2cj + 6dj (x − xj )
I 00 (x )/2; for j = 0, · · · , n − 1,
Define cn = Sn−1 n
00
2cj+1 = Sj+1 (xj+1 ) = Sj00 (xj+1 ) = 2cj + 6dj hj .
For j = 0, · · · , n − 1,
cj+1 − cj
2cj+1 = 2cj + 6dj hj , so dj =
3hj
aj+1 − aj hj aj+1 − aj
bj +cj hj +dj hj2 = , so bj = − (2cj +cj+1 )+ .
hj 3 hj
For j = 0, · · · , n − 2,
hj+1 aj+2 − aj+1
− (2cj+1 + cj+2 ) +
3 hj+1
hj aj+1 − aj
= − (2cj + cj+1 ) + + hj (cj + cj+1 ),
3 hj
cj+1 − cj hj aj+1 − aj
dj = , and bj = − (2cj + cj+1 ) + .
3hj 3 hj
Clamped Splines: S00 (x0 ) = f 0 (x0 ), Sn−1
0
(xn ) = f 0 (xn )
I Equation for c0 , c1 :
h0 a1 − a0
f 0 (x0 ) = S00 (x0 ) = b0 = − (2c0 + c1 ) + .
3 h0
a1 − a0
2h0 c0 + h0 c1 = 3 − f 0 (x0 ) .
h0
I Equation for cn−1 , cn :
f 0 (xn ) = Sn−1
0
(xn ) = bn = bn−1 + hn−1 (cn−1 + cn )
hn−1 an − an−1
= − (2cn−1 + cn ) + + hn−1 (cn−1 + cn ),
3 hn−1
which leads to
0 an − an−1
hn−1 cn−1 + 2hn−1 cn = 3 f (xn ) − .
hn−1
Clamped Splines: equations in matrix form
cj+1 − cj hj aj+1 − aj
dj = , and bj = − (2cj + cj+1 ) + .
3hj 3 hj
Clamped Splines
Natural Splines, f (x) = e x , x0 = 0, x1 = 1, x2 = 2, x3 = 3
Clamped Splines, f (x) = e x ,
x0 = 0, x1 = 1, x2 = 2, x3 = 3, f 0 (0) = 1, f 0 (3) = e 3
Splines
I Given n + 1 distinct points
(x0 , f (x0 )), (x1 , f (x1 )), · · · , (xn , f (xn )),
I Find cubic spline interpolant S(x) ∈ C 2 [x0 , xn ],
def
S(x) = Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3 ,
for x ∈ [xj , xj+1 ], 0 ≤ j ≤ n − 1.
I S(xj ) = f (xj ), 0 ≤ j ≤ n.
Two flavors of Splines
I A duck in flight
where
xj = x(tj ), yj = y (tj ), j = 0, 1, · · · , n.
I Example
Parametric Curve Approximation
I Polynomial interpolation on x = x(t), and y = y (t),
respectively.
352 14
x(t) = 64t − t + 60 t − t − 1,
3 3
64 116
y (t) = − t + 48 t − t + 11 t.
3 3
Parametric Curves in Computer Graphics
I Design: Piece-wise cubic Hermite polynomial.
I Feature: Each cubic Hermite polynomial is completely
determined by function/derivative at endpoints.
I Consequence:, Each portion of the curve can be changed
while leaving most of the curve the same.
such that
I Slopes
dy 1 dy −1
|t=0 = = 1, and |t=1 = = −1.
dx 1 dx 1
I The cubic Hermite polynomial x(t) = t satisfies
x(0) = 0, x(1) = 1, x 0 (0) = 1, and x 0 (1) = 1.
I Slopes
dy 1 dy −1
|t=0 = = 1, and |t=1 = = −1.
dx 1 dx 1
Numerical Differentiation
f (x0 + h) − f (x0 )
f 0 (x0 ) = lim
h→0 h
f (x0 + h) − f (x0 )
≈ for small values of h.
h
f (x0 + h) − f (x0 ) 1 00
f 0 (x0 ) = − h f (ξ)
h 2
f (x0 + h) − f (x0 )
≈ .
h
I forward-difference formula for h > 0,
I backward-difference formula for h < 0.
Numerical Differentiation
f (x0 + h) − f (x0 ) 1 00
f 0 (x0 ) = − h f (ξ)
h 2
f (x0 + h) − f (x0 )
≈ .
h
I forward-difference formula for h > 0,
I backward-difference formula for h < 0.
Numerical Differentiation, example
Example: Use the forward-difference formula to approximate the
derivative of f (x) = ln(x) at x0 = 1.8, using = 0.1, 0.05, 0.01.
!
n
X f (n+1) (ξ(x k ))
Y
f 0 (xk ) = f (xj )L0j (xk ) + (xk − xi )
(n + 1)!
j=0 i6=k
n
X
≈ f (xj )L0j (xk ).
j=0
1 1 000
f (x0 + h) = f (x0 ) + f 0 (x0 ) h + f 00 (x0 ) h2 + f (x0 ) h3
2 6
1 (4) 4
+ f (ξ+ ) h ,
24
1 1 000
f (x0 − h) = f (x0 ) − f 0 (x0 ) h + f 00 (x0 ) h2 − f (x0 ) h3
2 6
1 (4) 4
+ f (ξ− ) h .
24
Second order derivatives, equi-spaced points
1 1
f (x0 + h) = f (x0 ) + f 0 (x0 ) h + f 00 (x0 ) h2 + f 000 (x0 ) h3
2 6
1 (4) 4
+ f (ξ+ ) h ,
24
1 1
f (x0 − h) = f (x0 ) − f 0 (x0 ) h + f 00 (x0 ) h2 − f 000 (x0 ) h3
2 6
1 (4) 4
+ f (ξ− ) h .
24
Adding up, terms with difference signs cancel,
h4 (4)
f (x0 + h) + f (x0 − h) = 2f (x0 ) + f 00 (x0 ) h2 + f (ξ+ ) + f (4) (ξ− )
24
2h4 (4)
= 2f (x0 ) + f 00 (x0 ) h2 + f (ξ).
24
Second order derivatives, equi-spaced points
1 1
f (x0 + h) = f (x0 ) + f 0 (x0 ) h + f 00 (x0 ) h2 + f 000 (x0 ) h3
2 6
1 (4) 4
+ f (ξ+ ) h ,
24
1 1
f (x0 − h) = f (x0 ) − f 0 (x0 ) h + f 00 (x0 ) h2 − f 000 (x0 ) h3
2 6
1 (4) 4
+ f (ξ− ) h .
24
Adding up, terms with difference signs cancel,
h4 (4)
f (x0 + h) + f (x0 − h) = 2f (x0 ) + f 00 (x0 ) h2 + f (ξ+ ) + f (4) (ξ− )
24
2h4 (4)
= 2f (x0 ) + f 00 (x0 ) h2 + f (ξ).
24
Therefore
f (x0 + h) + f (x0 − h) − 2f (x0 ) h2 (4)
f 00 (x0 ) = − f (ξ).
h2 12
Round-Off Error Instability
f (x0 +h) = fb(x0 +h)+e(x0 +h) and f (x0 −h) = fb(x0 −h)+e(x0 −h),