L2_Interpolation

advertisement
MA2213 Lecture 2
Interpolation
Introduction
Problem : Find / evaluate a function P whose
values are specified on some set S
The specified values
P ( x),
x  S may arise from
measurements of a physical function f
(ground height, air velocity-pressure-temperature)
values of a mathematical function f
(cos, log, exp, solution of a differential equation)
Applications
Medicine, Entertainement, Earth Sciences
Computer Aided Design and Manufacturing
Image Processing, Computer Graphics and Vision
•
Applications of interpolation and area display in EEG.
– Applications of interpolation and area display in EEG. McGee FE Jr, Lee
RG, Harris JA, Melby G, Bickford RG.MeSH Terms Automatic Data
Processing* ...
An Efficient Spline Basis For Multi-dimensional Applications ...
File Format: PDF/Adobe Acrobat
In many applications, bilinear interpolation is. used instead of cubic splines
because of its simplicity in. implementation. When HDTV is realized, ...
http://der.topo.auth.gr/DERMANIS/PDFs/Erice.pdf
http://en.wikipedia.org/wiki/Linear_interpolation#Applications
http://skagit.meas.ncsu.edu/~helena/gmslab/viz/sinter.html
One Dimensional Case
Given a sequence of numbers x1  x2    xn1  xn
called nodes, and for each xk
a second number y k we are
looking for a function P so that
P( xk )  yk , k  1,..., n
A pair ( xk , yk ) is called a data point and P is
called an interpolant for the data points.
Example
Suppose we have a table like this,
which gives some values of an
unknown function f.
xk
yk
0
1
2
3
4
5
6
0
0.8415
0.9093
0.1411
−0.7568
−0.9589
−0.2794
( x3 , y3 )
( x4 , y4 )
Plot of the data points
as given in the table
What value does the function have at, say, x = 2.5?
Interpolation answers questions like this.
Choosing a Method
Plin (x)
Linear Interpolation
Ppol (x)
Polynomial Interpolation
There are many different interpolation methods, including
linear and polynomial. Some of the concerns to take into
account when choosing an appropriate method are: How
accurate is the method? How expensive is it? How smooth is
the interpolant? How many data points are needed?
Linear Interpolation
Formula for the linear interpolant on each of n-1 intervals
Plin ( x)  y k 
y k 1  y k
xk 1  xk
( x  xk ),
x  [ xk , xk 1 ]
( xk , yk )


( xk 1 , yk 1 )
Remark If n > 2 then the interpolant is not a linear
function, however, it is a piecewise linear function
Linear Interpolation Error
Definition The max error on the interval
[ xk , xk 1 ] is
Errork  max | f ( x)  Plin ( x) |, x [ xk , xk 1 ]
Graph of
( xk , yk )

x
f
 ( xk 1 , yk 1 )
Remark The error is clearly depends on f(x),
not only of the interpolation points.
Question Where does the max error occur ?
Linear Interpolation Error

The max error occurs at x  I  [ xk , xk 1 ]
where a  f ' ( x  )  ( yk 1  yk ) /( xk 1  xk )
If f has 2 continuous derivatives on I then
 2
1 "
f ( x)  P1 ( x)  2 f ( )( x  x ) where P1 ( x) 
P1 f ( x )  a( x  x )

is the deg 1 TP
( xk , yk )
x
x

 ( xk 1 , yk 1 )
f ( x  )  Plin ( x  )  P1 ( xk )  f ( xk )   12 f " ( k )( xk  x  ) 2


 2
1 "
f ( x )  Plin ( x )  P1 ( xk 1 )  f ( xk 1 )   2 f ( k 1 )( xk 1  x )


| f ( x )  Plin ( x ) |  ( xk 1  xk ) max | f ( x) |, x  [ xk , xk 1 ]
1
8
2
"
Linear Interpolation Basis Functions
k
1
x1
x2
xk 1 xk
x2  x
 1 ( x) 
,
x2  x1
x  xk 1
 k ( x) 
,
xk  xk 1
xk 1  x
 k ( x) 
,
xk 1  xk
x  xn 1
 n ( x) 
,
xn  xn 1
n
xk 1
xn 1
x  [ x1 , x2 ]
x  [ xk 1 , xk ], k  2,..., n  1
x  [ xk , xk 1 ], k  2,..., n  1
x  [ xn 1 , xn ]
xn
Linear Interpolation Basis Functions
k
1
x1
n
xk 1 xk
x2
xk 1
 k ( x j )  1,
jk
 k ( x j )  0,
jk
xn 1
xn
n
Plin ( x)   yk  k ( x)
k 1
Question Why is
Plin (x)
piecewise linear ?
Polynomial Interpolation
If
Ppoly ( x)  a0  a1 x    an1 x
and
Ppoly ( xi )  yi , i  1,..., n
1 x1
 a0   y1 

 a  y 
1
x
1
2
2





where
V

V
 
   


  
1 xn
an 1   yn 
det V 
i
i 2
then


 x 
  
n 1 
 xn 
n 1
1
n 1
2
 x
i 1
  x x  
n
n 1
j 1
j
0  unique solution
Lagrange Basis Functions
Lk
x1
x2
xk 1 xk
xk 1
xn 1
xn
( x  x1 )  ( x  xk 1 )( x  xk 1 )  ( x  xn )
Lk ( x) 
( xk  x1 )  ( xk  xk 1 )( xk  xk 1 )  ( xk  xn )
Lk ( x j )  1, j  k , Lk ( x j )  0, j  k
n
Ppol ( x)   yk Lk ( x)
k 1
Question What is degree
Ppol (x)
?
Polynomial Interpolation Error
Theorem 5.3 (page 121)
If f has n continuous derivatives on [a,b] and
a  x1    xn  b and Ppol (x)
is the unique polynomial of degree  n 1
that satisfies Ppol ( xi )  f ( xi ), i  1,..., n
and x  [ a, b] then  c( x)  [a, b] 
f ( x)  Ppol ( xi )  ( x  x1 )  ( x  xn ) f (c( x))
1
|
f
(
x
)

P
(
x
)
|

Corollary
pol
n ! M n | n ( x) |
1
n!
M n  max | f
(n)
(n)
( x) |, x  [a, b] n ( x)  ( x  x1 ) ( x  xn )
Polynomial Interpolation Error
Example sin(.32)=.314567 , sin(.34)=.333487 ,
sin(.36) = .352274 , compute sin(.3367)
Solution Using piecewise linear interpolation
.34
.3367.32
sin(. 3367)  .3367

.
314567

.32.34
.34.32  .333487
 .33036520
sin(. 3367)  .33037419
Error  .33037419  .3303652  8.980e  006
1
2!
M 2 ( x)  12 sin(. 34) ( x)  9.189e  006
Polynomial Interpolation Error
Example sin(.32)=.314567 , sin(.34)=.333487 ,
sin(.36) = .352274 , compute sin(.3367)
Solution using quadratic interploation
x  .3367, y  sin( x)  .33037419155563
x1  .32, x2  .34, x3  .36, yi  sin( xi ), i  1,2,3
( x  x2 )( x  x3 )
Pquad ( x)  y1
   0.33037439336976
( x1  x2 )( x1  x3 )
Error  P  y  2.0181e  007
1
3!
M 3 ( x)  16 cos(.32) ( x)  2.0315e  007
Divided Differences
f ( x2 )  f ( x1 )
f [ x1 , x2 ] 
x2  x1
f [ x2 , x3 ]  f [ x1 , x2 ]
f [ x1 , x2 , x3 ] 
x3  x1

f [ x2 , , xn ]  f [ x1 ,, xn 1 ]
f [ x1 ,, xn ] 
xn  x1
Theorem If x1  x2    xn and
(n -1)
f
is continuous then
 c  [ x1 , xn ]  f [ x1 ,, xn ]  ( n11) ! f ( n1) (c)
Divided Differences Properties
Invariance under permutation
f [ x1 , x2 ]  f [ x2 , x1 ]
f [ x1 , x2 , x3 ]  f [ x2 , x1 , x3 ]  f [ x2 , x3 , x1 ]  

f [ x1 , x2 ,, xn ]  f [ x2 , x1 ,, xn ]  
'
If f is continuous then
(n -1)
lim f [ x1 , x2 ]  f ' ( x1 )
x 2  x1
Definition If f
is continuous then
(n -1)
1
we define f [ x1 ,, x1 ]  ( n1) ! f ( x1 )
Divided Differences Computation
For x1  x2  x3  x4
x1 f ( x1 )
x2 f ( x2 ) f [ x1 , x2 ]
x3 f ( x3 ) f [ x2 , x3 ] f [ x , x , x ]
1
2
3
x4 f ( x4 ) f [ x3 , x4 ] f [ x , x , x ] f [ x , x , x , x ]
2
3
4
1
2
3
4
Question: How smooth must
f be at repeated values of x ?
Newton’s Interpolation Formula
Let Pn1 ( x) denote the unique polynomial
of degree < n that interpolates a
function f at points x1    xn
This means that Pn1 ( xi )  f ( xi ), i  1,..., n
Then Pn1 ( x)  f ( x1 )  ( x  x1 )f [ x1 , x2 ]  
 ( x  x1 )( x  x2 ) ( x  xn1 )f [ x1 , x2 ,, xn ]
Question How can the interpolant be
computed recursively ‘point by point’ ?
Natural Cubic Splines
Problem Given x1    xn , y1 ,, yn
2
find a function s  C ([ x1 , xn ]) such that
s( xi )  yi , i  1,..., n and that minimizes
x
2


[
s
(
x
)]
dx
among all functions that
x
satisfy the interpolatory constraint.
Solution Unique function s described on
pp.131-134 of Atkinson. Its restriction to
each interval [ xi , xi 1 ], i  1,..., n  1 is a
cubic polynomial determined by yi , yi 1
and parameters satisfying linear eqns.
n
1
Natural Cubic Splines
s ( x) 
( x j  x ) 3 M j 1  ( x  x j 1 ) 3 M j
6 ( x j  x j 1 )

( x j  x ) y j 1  ( x  x j 1 ) y j
x j  x j 1
 16 ( x j  x j 1 )[( x j  x) M j 1  ( x  x j 1 ) M j ], x  [ x j 1 , x j ]
where M 1  M n  0 and
x j  x j 1
6
y j 1  y j
x j 1  x j
M j 1 


x j 1  x j 1
3
y j  y j 1
x j  x j 1
Mj 
x j 1  x j
6
, j  2,..., n  1
Splines – are serious business !
M j 1
Homework Due at End of Lab 1
Question 1. Write and use a MATLAB program
to solve problem 1. a. on page 77 using the
bisection method. Make a plot of the errors as
a function of the number of iterations.
Question 2. Write and use a MATLAB program
to find the real root of the polynomial (in the
previous question) using Newton’s method. Make
a plot of the errors as a function of the number of
iterations.
Suggested Reading: pages 117-159
Appendix B. Mathematical Formulas
Download