You are on page 1of 25

Interpolation

Gerald Recktenwald
Portland State University
Mechanical Engineering Department
gerry@me.pdx.edu

These slides are a supplement to the book Numerical Methods with


Matlab: Implementations and Applications, by Gerald W. Recktenwald,
c 2002, Prentice-Hall, Upper Saddle River, NJ. These slides are  c
2002 Gerald W. Recktenwald. The PDF version of these slides may
be downloaded or stored or printed only for noncommercial, educational
use. The repackaging or sale of these slides in any form, without written
consent of the author, is prohibited.

The latest version of this PDF file, along with other supplemental material
for the book, can be found at www.prenhall.com/recktenwald.

Version 0.01 March 9, 2002


Primary Topics

• Interpolating polynomials of arbitrary degree


 Monomial basis
 Lagrange basis
 Newton basis
• Piecewise polynomial interpolation
 Linear
 Hermite polynomials
 Cubic splines
• Matlab’s built-in interpolation routines

NMM: Interpolation page 1


Figure 10.2

11 12 1
10 2
9 3
60 80 100
12 8 4
40 0
1
0 kmh 7 5
4
2

6
0

NMM: Interpolation page 2


Figure 10.3

12

10
Viscosity (N⋅ s)/m2

0
0 10 20 30 40 50
Temperature (C)

NMM: Interpolation page 3


Figure 10.4

known data
y curve fit
interpolation

NMM: Interpolation page 4


Figure 10.5

y2 y3
y2

y1 y1

x1 x2 x1 x2 x3

NMM: Interpolation page 5


Figure 10.6

30

historic data
linear
quadratic
25 cubic
spline

20
Millions of passengers

?
15

10

0
1980 1985 1990 1995 2000 2005 2010

NMM: Interpolation page 6


Figure 10.7

145

140
gasoline price, (cents)

135

130
1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
year

NMM: Interpolation page 7


Figure 10.8

145

140
gasoline price, (cents)

135

130
1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
year

NMM: Interpolation page 8


Figure 10.9

y2
1
L1(x) L2(x)

y1
0 0
x1 x2 x1 x2

NMM: Interpolation page 9


Figure 10.10

degree 1 degree 2
1.5 1.5

1 1

0.5 0.5

0 0

-0.5 -0.5
1 2 3 4 5 1 2 3 4 5

degree 3 degree 4
1.5 1.5

1 1

0.5 0.5

0 0

-0.5 -0.5
1 2 3 4 5 1 2 3 4 5

NMM: Interpolation page 10


Table 10.1

xi f[] f [,] f [,,] f [,,,]

x1 f [x1]

x2 f [x2] f [x1, x2]

x3 f [ x3] f [x2, x3] f [x1, x2, x3]

x4 f [x4] f [x3, x4] f [x2, x3, x4] f [x1, x2, x3, x4]

NMM: Interpolation page 11


Diagonals of Divided-Difference Table

xi f[] f [,] f [,,] f [,,,]

x1 c1

x2 c2 c2

x3 c3 c3 c3

x4 c4 c4 c4 c4

NMM: Interpolation page 12


Figure 10.11

6
10
monomial
Lagrange
Newton
5
10

4
10
Flops

3
10

2
10

1
10 0 1 2 3
10 10 10 10
Number of points to interpolate

NMM: Interpolation page 13


Figure 10.12

5 5

0 0

-5 -5
0 2 4 6 8 10 0 2 4 6 8 10

5 5

0 0

-5 -5
0 2 4 6 8 10 0 2 4 6 8 10

5 5

0 0

-5 -5
0 2 4 6 8 10 0 2 4 6 8 10

5 5

0 0

-5 -5
0 2 4 6 8 10 0 5 10

NMM: Interpolation page 14


Figure 10.13

1.5

0.5

0
0 1 2 3 4 5 6

1.5

0.5

0
0 1 2 3 4 5 6

0
0 1 2 3 4 5 6

NMM: Interpolation page 15


Figure 10.14

'
fi+2, fi+2
'
fi+1, fi+1
Pi+1(x)
Pi(x)
fi , fi'

xi xi+1 xi+2

NMM: Interpolation page 16


Figure 10.15

P4(x) P5(x)
P2(x) P3(x)

P1(x)

x1 x2 x3 x4 x5 x6

NMM: Interpolation page 17


Figure 10.16

0.5 0.5
Given Given
0.4 x*exp(-x) 0.4 x*exp(-x)
Hermite Hermite
0.3 0.3

0.2 4 knots 0.2 6 knots

0.1 0.1

0 0
0 2 4 6 8 0 2 4 6 8

0.5 0.5
Given Given
0.4 x*exp(-x) 0.4 x*exp(-x)
Hermite Hermite
0.3 0.3

0.2 8 knots 0.2 12 knots

0.1 0.1

0 0
0 2 4 6 8 0 2 4 6 8

NMM: Interpolation page 18


Figure 10.17

segments coupled
´´ (xi) = Pi´´(xi)
by Pi–1
Pn–2(x)
P2(x) Pn–1(x)
P1(x) Pi–1(x) P (x)
i

x1 x2 x3 xi–1 xi xi+1 xn–2 xn–1 xn

NMM: Interpolation page 19


Figure 10.18

no curvature

no curvature

NMM: Interpolation page 20


Figure 10.19

Natural end conditions Zero slope end conditions


0.5 0.5
knots knots
0.4 spline 0.4 spline
x*exp(-x) x*exp(-x)
0.3 0.3

0.2 0.2

0.1 0.1

0 0
0 2 4 6 0 2 4 6

Not a knot end conditions Exact slope end conditions


0.5 0.5
knots knots
0.4 spline 0.4 spline
x*exp(-x) x*exp(-x)
0.3 0.3

0.2 0.2

0.1 0.1

0 0
0 2 4 6 0 2 4 6

NMM: Interpolation page 21


Figure 10.20

100 100
Nearest neighbor Piecewise linear

50 50

0 0

0 0.5 1 1.5 0 0.5 1 1.5

100 100
Piecewise cubic Cubic spline

50 50

0 0

0 0.5 1 1.5 0 0.5 1 1.5

NMM: Interpolation page 22


Exercise 10.20

6
5
y 4
3
2
1
0
-1 0 1 2 3 4
x

NMM: Interpolation page 23


Exercise 10.37

6
t=5
5
y 4 t=2
t=4
3 t=3
2
1 t=1
0
-1 0 1 2 3 4
x

NMM: Interpolation page 24

You might also like