Upload
derrick-flowers
View
215
Download
0
Embed Size (px)
Citation preview
2005. 05. 112003010482 Mohiuddin Ahmad
2005010207 SUNG-BONG JANG
Interpolation IIInterpolation II(8.4 SPLINE INTERPOLATION)(8.4 SPLINE INTERPOLATION)
(8.5 MATLAB’s INTERPOLATION Functions)(8.5 MATLAB’s INTERPOLATION Functions)
Computer Vision and Pattern Recognition Lab.
Mohiuddin Ahmad ([email protected])ID: 2003010482
Computer Vision and Pattern Recognition Lab.Dept. of Computer Science and Engineering
Korea University
8.4 : Spline Interpolation8.4 : Spline Interpolation
Computer Vision and Pattern Recognition Lab.
Spline Interpolation
Interpolation qualities Piecewise polynomial Want smooth curves Local control
Local data changes have local effect Continuous with respect to the data
No wiggling if data changes slightly Low computational effort
Items to be discussed Piecewise linear interpolation Piecewise quadratic interpolation Cubic spline interpolation
Computer Vision and Pattern Recognition Lab.
Spline Interpolation
Piecewise Linear Interpolation Simplest form of piecewise polynomial interpolation
Interpolate the data with piecewise linear function
432144332211 with ),(),,(),,(),,( :points data ofSet xxxxyxyxyxyx
],[ ],,[ ],,[ ,lssubinterva threeDefine 433322211 xxIxxIxxI
43434
33
43
4
32323
22
32
3
21212
11
21
2
,
,
,
)(
xxxyxx
xxy
xx
xx
xxxyxx
xxy
xx
xx
xxxyxx
xxy
xx
xx
xP
),( 11 yx
),( 22 yx
),( 33 yx
),( 44 yx
x
y
Computer Vision and Pattern Recognition Lab.
Piecewise Linear Interpolation
Example 8.14 Piecewise Linear Interpolation
Function is continuous, but not smooth
]3 4 1 0[ ],3 2 1 0[ Using, yx
32 ,6
21 ,23
10 ,
)(
xx
xx
xx
xP
0 1 2 30
1
2
3
4
x
y
Figure 8.18 Piecewise linear interpolation
Computer Vision and Pattern Recognition Lab.
Piecewise Quadratic Interpolation
“Knots” Where the intervals meet to be the midpoints between the data
points where the function values are given
Processing 4 data points Define node points
Spacing between consecutive data points
Relationships:
432144332211 with ),(),,(),,(),,( xxxxyxyxyxyx
4543432321211 ,2/)( ,2/)( ,2/)( , xzxxzxxzxxzxz
343232121 , , xxhxxhxxh
),( 11 yx121 xxh
),( 33 yx
),( 44 yx
x
y
232 xxh 343 xxh
1z 2z 3z 4z 5z
2/
,2/
,2/
334
223
112
hxz
hxz
hxz
2/
,2/
,2/
344
233
122
hxz
hxz
hxz
Computer Vision and Pattern Recognition Lab.
Piecewise Quadratic Interpolation
We define
Since,
Equations at the interior nodes [impose continuity condition
on the polynomials]
;)()()( :],[on
;)()()( :],[on
;)()()( :],[on
;)()()( :],[on
4442
444544
3332
333433
2222
222322
1112
111211
cxxbxxaxPzzP
cxxbxxaxPzzP
cxxbxxaxPzzP
cxxbxxaxPzzP
);(422 :)( )(
);(422 :)( )(
);(422 :)( )(
3443334233
234443
2332223222
223332
1221112211
212221
yybhbhahahzPzP
yybhbhahahzPzP
yybhbhahahzPzP
4 ,3 ,2 ,1for ,)( ,re therefo,)( kycyxPcxP kkkkkkkk
Computer Vision and Pattern Recognition Lab.
Piecewise Quadratic Interpolation
Equations at the interior nodes [impose continuity condition
on the first derivative of the polynomials]
We have 6 equations & 8 unknown coefficients (a1, a2, a3, a4, b1, b2, b3, b4)
;0 :)( )(
;0 :)( )(
;0 :)( )(
4343334443
3232223332
2121112221
bbahahzPzP
bbahahzPzP
bbahahzPzP
0 and 0
0)(2 gives 0)(
0)(2 gives 0)(
Setting,
and determinecan We
)(2)( Since
41
444444
111111
41
bb
bxxaxP
bxxaxP
bb
bxxaxP kkkk
.0
,0
,0
),(42
),(422
),(42
33433
322322
21211
1233234
233
122322223
222
1212212
211
bhaha
bbhaha
bhaha
yyhbhaha
yyhbhbhaha
yyhbhaha
Equations for the coefficients at the zero slope
conditions at the end points of the interval
Computer Vision and Pattern Recognition Lab.
Piecewise Quadratic Interpolation – Example
Example : 8: 15 )3,3( ),4,2( ),1,1( ),0,0( :points Data
101100
110110
010011
201100
220110
020011
A
.0004124 r
:,,,,, tscoefficien :Solution 324321 bbaaaa
]9143.05143.24571.23714.37714.17429.0[x
on elliminatiGaussian Using
3.0] [2.5,on 3)3(4571.2)(
2.5] [1.5,on 4)2(9143.0)2(3714.3)(
1.5] [0.5,on 1)1(5143.2)1(7714.1)(
0.5] [0.0,on )0(7429.0)(
24
23
22
21
xxP
xxxP
xxxP
xxP
Piecewise interpolating polynomial
0 1 2 3 0
1
2
3
4
x
Piecewise quadratic interpolation of four data pointsy
Computer Vision and Pattern Recognition Lab.
Piecewise Cubic Interpolation
Cubic splines → piecewise cubic polynomial
Calculation of the coefficients of cubic polynomial
Cubic spline function, S(x)
iii
nnii
xxh
yxyxyxyx
nn
1
2211
valuesbetween x Spacing
),........(),........,( ......,..........),,(),,(
intervals sub 1pointsgiven
2.order toup derivative continuous with cubic piecewiseA
),(
, ),(
, , )(
)(
:form theoffunction Spline
11
1
211
nnn
iii
xxxxP
xxxxP
xxxxP
xS),( 11 yx
),( 22 yx
),( 33 yx
),( 44 yx
x
y),( nn yx
1h 2h 3h 1nh
),( 11 nn yx
Computer Vision and Pattern Recognition Lab.
Piecewise Cubic Interpolation
Cubic spline function S(x), n-cubic polynomials Pi(x) with coefficients pi,0, pi,1, pi,2, and pi,3 satisfy the following properties:
1. S(x) consists of piecewise cubic (I)2. Piecewise cubic interpolate the given set of data points (II)3. Piecewise cubics represent a smooth continuous function (III & IV)4. Second derivative of the resulting function is continuous (V)
S(x) is piecewise cubic, S//(x) is linear on [x0, xn-1].
.
.2,....,1,0for )( V.
.2,....,1,0for )( IV.
.2,....,1,0for )( III.
.1,....,1,0for )( II.
.1,....,1,0for
)()()()()( I.
111
111
111
33,
22,1,0,
ni)(xPxP
ni)(xPxP
ni)(xPxP
niyxS
ni
xxpxxpxxppxPxS
iiii
iiii
iiii
ii
iiiiiiii
(x)P(x)SxSxx
xxxS
xx
xxxP ii
ii
ii
ii
ii
for ion interpolat LagrangeLinear ),()()( 111
1
Computer Vision and Pattern Recognition Lab.
Piecewise Cubic Interpolation
Use S//(xi)=ai-1 , S//(xi+1)=ai and hi=xi+1 – xi, we get,
Integrating twice will introduce two constant of integration, and the cubic function is
From, definition of hi ,
Integrating P//i(x) twice and using Pi(xi) =yi & Pi (xi+1 ) =yi+1 :
Determine the value of bi and ci
.
)()(6
)(
6
)()(
write we,1,.......,1 For,
1
331
1 iiiii
ii
i
iii xxcxxb
h
xxa
h
xxaxP
ni
iiiiii axPaxP )( and )( 111
6 and ,
611 ii
i
ii
ii
i
ii
ha
h
yc
ha
h
yb
i
ii
i
iii h
xxa
h
xxaxP
1
1)(
Computer Vision and Pattern Recognition Lab.
Piecewise Cubic Interpolation
Construction of cubic spline From property IV, 1st derivative of Pi and Pi+1 must agree at xi+1
Natural cubic spline assigns, 2nd derivative is zero at the endpoints
Error in cubic spline interpolation is |S(x) – g(x) | S(x) : spline interpolation function g(x) : function that generated the data Let, h : maximum spacing between node points, G=max|g(4)(x)|. Condition: |S(x) – g(x) | < kh4G =O(h4)
)2,...,1(636
1
1
121
111
ni
h
yy
h
yya
ha
hha
h
i
ii
i
iii
ii
iii
i
),,.........( unknowns for equations 2 : 10 naann
0 and 0 10 naa
Computer Vision and Pattern Recognition Lab.
Choice of Two Additional Conditions
End point constraints for a cubic spline
Description of the strategy Equation involving a0 and an
(i) Clamped cubic spline: specify
S/(x0), S/(xn)
(ii) Natural cubic spline
(iii) Extrapolated S//(x) to the end
points
(iv) S//(x) is constant near the end
points
(v) Specify S//(x) at each endpoint
00 a 0na
1
120 )(10 h
aahaa
2
2111
)(
n
nnnnn h
aahaa
110 , nn aaaa
)( ),( 00 nn xSaxSa
2))(( 1
003
00
axSda
h
2))(( 1
13
1
nnnhn
adxSa
n
i
ii
hyy
id 1
Computer Vision and Pattern Recognition Lab.
Example 8.16 Natural Cubic Spline Interpolation
Example 8:16
);()( 6
1
3
2
6
1 :3i
);()( 6
1
3
2
6
1 :2i
);()( 6
1
3
2
6
1 :1i
:follows as ,,for equation The spline. cubic natural afor 0 and
intervals,each for 1).8,2( and (1,1) ),2,0( ),1,1( ),4,2( :points dataConsider
3445432
2334321
1223210
32040
yyyyaaa
yyyyaaa
yyyyaaa
aaaaa
hi
4286.15 ,7143.13 ,4286.15
system nal tridiagoa gives
484
244
484
gsimplifyin and )5,..1( and ,,for values thengSubstituti :1
321
32
321
21
40
aaa
aa
aaa
aa
iyaaStep i
5714.16/
,2857.46/
,5714.36/
,46/
gives for Solving :2
344
233
122
011
ayb
ayb
ayb
ayb
bStep i
.86/
,5714.16/
,2857.46/
,5714.36/
gives cfor Solving :3
454
343
232
121
ayc
ayc
ayc
ayc
Step i
Computer Vision and Pattern Recognition Lab.
Example 8.16 Natural Cubic Spline Interpolation
Example 8:16 – cont’d
21 ),1(8)2(57.1)2(57.2
,10 ,57.1)1(29.457.2)1(29.2
,01 ),1(29.457.3)1(29.2 57.2
,12 ),2(57.3)1(4 )2(57.2
:
: tosimplifies spline cubic The
3
33
33
3
xxxx
xxxxx
xxxxx
xxxx
S(x) -2 -1 0 1 2-2
0
2
4
6
8
x
y
Figure 8.20 Cubic spline interpolant
Computer Vision and Pattern Recognition Lab.
Matlab function for Natural Cubic Spline
Matlab code
Computer Vision and Pattern Recognition Lab.
Matlab function for Natural Cubic Spline
Computer Vision and Pattern Recognition Lab.
Example 8.17 Runge Function
)251/(1)( 2xxf ];0385.01379.00.11379.00385.0[
];0.15.00.05.01[
y
x
i
ii
i
iii
ii
iii
i
h
yy
h
yya
ha
hha
h
,......, ni
1
1
121
111 636
11for
5.0 ,Here 4321 hhhh
3048.184
3808.414
3048.18 4
spline, cubic natural considered As
32
321
21
aa
aaa
aa
Using tridiagonal solution
a1 = 8.1857, a2 = -14.4381, a3 = 8.1857
Solving for bi & ci gives
b1 = 0.0770, b2 = -0.4043, b3 = 3.2032, b4 = -0.4043
c1 = -0.4043, c2 = 3.2032, c3 = -0.4043, c4 = 0.0770-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
-0.2
0
0.2
0.4
0.6
0.8
1
1.2
0.10.5 ),5.0(077.0)1(4043.0)1(7286.2
5.0.00 ,4043.0)5.0(2032.3)(7286.2)5.0(8127.4
0.00.5 ),5.0(2032.3)(4043.0)5.0(8127.4)(7286.2
5.01.0 ),1(4043.0)5.0(077.0)1(7286.2
)(
tosimplifies Spline Cubic
3
33
33
3
xxxx
xxxxx
xxxxx
xxxx
xS
Computer Vision and Pattern Recognition Lab.
Example 8.17 Runge Function
],0385.00664.0138.03902.00.13902.0138.00664.00385.0[
],0.175.050.025.000.025.050.075.00.1[
y
x
)2,...,1(636
1
1
121
111
ni
h
yy
h
yya
ha
hha
h
i
ii
i
iii
ii
iii
i
25.0 ,Here 87654321 hhhhhhhh
3048.184
3048.184
3048.184
3048.184
3048.184
3808.414
3048.18 4
spline, cubic natural considered As
76
765
654
543
432
321
21
aa
aaa
aaa
aaa
aaa
aaa
aa
Using tridiagonal solution
a1= 1.2221; a2 = -0.6067; a3= 18.3695; a4=-38.4551; a5=18.3695; a6=-0.6067; a7=1.2221;
Consider natural cubic spline, a0 = 0; a8 = 0;
Solving for bi & ci gives
b1 = 0.1540, b2 = 0.2147, b3 = 0.5809, b4 = 0.7954, b5 = 5.6023, b6 = 0.7954, b7 = 0.5809, b8 = 0.2147
c1 = 0.2147, c2 = 0.5809, c3 = 0.7954, c4 = 5.6023, c5 = 0.7954, c6 = 0.5809, c7 = 0.2147, c8 = 0.1540
Computer Vision and Pattern Recognition Lab.
Example 8.17 Runge Function
Cubic spline simplifiesp1 = 1.2221 *( x + 1.0 ).^3 / 1.5 + 0.1540*( -0.75 - x) + 0.2147 *(x + 1.0 ) ; -1 ≤x ≤ -0.75 ;
p2 = 1.2221*(-0.5 - x).^3 / 1.5 - 0.6067 * (x + 0.75 ).^3 / 1.5 + 0.2147*( -0.50 - x) + 0.5809 *(x + 0.75 ); -0.75 ≤x ≤ -0.50 ;
p3 = -0.6067*(-0.25 - x).^3 / 1.5 + 18.3695 * (x + 0.50 ).^3 / 1.5 + 0.5809*(-0.25 - x) + 0.7954 * (x + 0.5 ) ; -0.50 ≤x ≤ -0.25 ;
p4 = 18.3695*(-0.0 - x).^3 / 1.5 - 38.4551 * (x + 0.25 ).^3 / 1.5 + 0.7954 *(-0.0 - x) + 5.6023 * (x + 0.25 ); -0.25 ≤x ≤ 0.0 ;
p5 = -38.4551*(0.25 - x).^3 / 1.5 + 18.3695 * (x + 0.00 ).^3 / 1.5 + 5.6023 *(0.25 - x) + 0.7954 * (x + 0.00 ) ; 0.0 ≤x ≤ 0.25 ;
p6 = 18.3695*(0.5 - x).^3 / 1.5 - 0.6067 * (x - 0.25 ).^3 / 1.5 + 0.7954 *(0.50 - x) + 0.5809 * (x - 0.25 ) ; 0.25 ≤x ≤ 0.50 ;
p7 = -0.6067*(0.75 - x).^3 / 1.5 + 1.2221 * (x - 0.50 ).^3 / 1.5 + 0.5809 *(0.75 - x) + 0.2147 * (x - 0.50 ); 0.5 ≤x ≤ 0.75 ;
p8 = 1.2221*(1.00 - x).^3 / 1.5 + 0.0000 * (x - 0.75 ).^3 / 1.5 + 0.2147 *(1.00 - x) + 0.1540 * (x - 0.75 ) ; 0.75 ≤x ≤ 1.00 ;
-1 -0.5 0 0.5 10
0.2
0.4
0.6
0.8
1
spline function
actual Runge func.end points
x
y
Figure 8.21 Cubic spline interpolant of Runge function
Computer Vision and Pattern Recognition Lab.
Example 8.18, Chemical Reaction Product Data
Chemical reaction of data
Conclusion: Curve is smoother than higher
degree polynomial [ Fig. 8.6] Additional data points do not
really improve the appearance of original curve [Fig. 8.5]
]31.031.030.029.029.027.026.025.021.019.017.006.000.0[
]00.290.160.150.140.110.100.190.060.050.040.010.000.0[
x
x
0 0.5 1 1.5 20
0.05
0.1
0.15
0.2
0.25
0.3
0.35
x
y
Figure 8.22 Cubic spline interpolant of chemical reaction data
Computer Vision and Pattern Recognition Lab.
Example: 8.19 Difficult data
Data points:
Tridiagonal system of equations:
]0 0 0 0.87 1 0.87 0 0 0[
]2 1.5 1 0.5 0 0.5 1 1.5 2[
y
x
Using tridiagonal system
a0 = 0
a1= -1.8408
a2= 7.3633
a3= -6.7324
a4=1.8062
a5= -6.7324
a6= 7.3633
a7=-1.8408
a8 = 0
)2,...,1(636
1
1
121
111
ni
h
yy
h
yya
ha
hha
h
i
ii
i
iii
ii
iii
i
5.0 ,Here 87654321 hhhhhhhh
0.04
88.204
76.174
24.64
76.174
88.204
0.0 4
spline, cubic natural considered As
76
765
654
543
432
321
21
aa
aaa
aaa
aaa
aaa
aaa
aa
Solving for bi & ci gives
b1 = 0,
b2 = 0.1534,
b3 = -0.6136,
b4 = 2.3010,
b5 = 1.8495,
b6 = 2.3010,
b7 = -0.6136,
b8 = 0.1534
c1 = 0.1534,
c2 = -0.6136,
c3 = 2.3010,
c4 = 1.8495
c5 = 2.3010,
c6 =-0.6136,
c7 = 0.1534,
c8 = 0
Computer Vision and Pattern Recognition Lab.
Example: 8.19 Difficult data – cont’d
Resulting piecewise function made the following polynomial
0.25.1 ),5.1(0.0)2(15.03/)2(84.1
5.10.1 ),1(15.0)5.1(61.03/)1(84.13/)5.1(36.7
0.15.0 ),5.0(61.0)1(30.23/)5.0(36.7)1(24.2
5.00.0 ,30.2)5.0(85.1)(24.2)5.0(60.0
0.05.0 ),5.0(85.1)(30.2)5.0(60.0)(24.2
5.00.1 ),1(30.2)5.0(61.0)1(24.2)5.0(45.2
0.15.1 ),5.1(61.0)0.1(15.0)5.1(45.2)1(61.0
5.10.2 ),2(15.0)2(61.0
338
337
336
335
334
333
332
31
xxxxP
xxxxxP
xxxxxP
xxxxxP
xxxxxP
xxxxxP
xxxxxP
xxxP
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2-0.2
0
0.2
0.4
0.6
0.8
1
1.2
x
y
Figure 8.23 Cubic spline interpolant of humped and flat data
2005. 05. 11
2005010207 SUNG-BONG JANG
Interpolation IIInterpolation II(8.5,MATLAB’s INTERPOLATION Functions)(8.5,MATLAB’s INTERPOLATION Functions)
26 / 7
■ 8.5.1 Interpolation in One-Dimensional
8.5.1.1 MATLAB function : Interp1
8.5.1.2 yy = interp1(x,y,xx,method) : interpolates using alternative methods:
‘linear‘ : Linear interpolation (default)
'nearest‘ : Nearest neighbor interpolation
‘cubic’ : Piecewise cubic Hermite interpolation
'spline‘ : Cubic spline interpolation
8.5.1.3 method : linear
x = 0:10;
y = sin(x);
xi = 0:.25:10;
yi = interp1(x,y,xi);
plot(x,y,'o',xi,yi)
0 1 2 3 4 5 6 7 8 9 10-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
27 / 7
■ 8.5.1 Interpolation in One-Dimensional
8.5.1.4 method : nearest
x = 0:10;
y = sin(x);
xi = 0:.25:10;
yi = interp1(x,y,xi,’nearest’);
plot(x,y,'o',xi,yi)
8.5.1.5 method : cubic
x = 0:10;
y = sin(x);
xi = 0:.25:10;
yi = interp1(x,y,xi,’cubic’);
plot(x,y,'o',xi,yi)
0 1 2 3 4 5 6 7 8 9 10-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
0 1 2 3 4 5 6 7 8 9 10-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
28 / 7
■ 8.5.1 Interpolation in One-Dimensional
8.5.1.6 method : spline
x = 0:10;
y = sin(x);
xi = 0:.25:10;
yi = interp1(x,y,xi,’spline’);
plot(x,y,'o',xi,yi)
8.5.1.7 Faster methods
- the data are given at equally spaced intervals(i.e, x is equally spaced and monotonic): *linear,*cubic,*spline
> What is Monotonic ? : A function which is either entirely nonincreasing or nondecreasing.
A function is monotonic if its first derivative (which need not be continuous) does not
change sign.
- the data that are not uniformly spaced : interp1q.
- MATLAB ‘plot’ function : linear interpolation
0 1 2 3 4 5 6 7 8 9 10-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
29 / 7
■ 8.5.2 Interpolation in Two Dimensionals
8.5.2.1 Overview
- much more difficult than for a single variable.
- Defined on a rectangular grid : z(i,j) = f(x(i),y(j));
- Interp2 : three ways in which the interp2 can be used.
> ZI = interp2(Z,ntimes) expands Z by interleaving interpolates
between every element, working recursively for ntimes. interp2(Z) is the same as interp2(Z,1).
> ZI = interp2(Z,XI,YI) assumes that X = 1:n and Y = 1:m, where [m,n] = size(Z).
> ZI = interp2(X,Y,Z,XI,YI) returns matrix ZI containing elements corresponding to the elements of
XI and YI and determined by interpolation within the two-dimensional function specified by matrices X, Y, and Z.
30 / 7
8.5.2.2 ZI = interp2(Z,ntimes)
- expands the data matrix z by interleaving interpolanes between every element.
xx = [x1, (x2 + x2)/2, x2,….,(xn-1 + xn-1)/2, xn ]
yy = [y1, (y2 + y2)/2, y2,….,(yn-1 + yn-1)/2, yn ]
- zz = interp2(z); zz = interp2(z,k)
- Example)
x=[2,4], y =[3,5,7], z= x’y, >> interp2(z)
ans =
6 8 10 12 14
9 12 15 18 21
12 16 20 24 28
>> interp2(z,2)
ans =
6.0000 7.0000 8.0000 9.0000 10.0000 11.0000 12.0000 13.0000 14.0000
7.5000 8.7500 10.0000 11.2500 12.5000 13.7500 15.0000 16.2500 17.5000
9.0000 10.5000 12.0000 13.5000 15.0000 16.5000 18.0000 19.5000 21.0000
10.5000 12.2500 14.0000 15.7500 17.5000 19.2500 21.0000 22.7500 24.5000
12.0000 14.0000 16.0000 18.0000 20.0000 22.0000 24.0000 26.0000 28.0000
- mesh(x,y,z’)
* mesh(X,Y,Z) : draws a wireframe mesh with color determined by Z so color is proportional to surface height. If X and Y are vectors, length(X) = n and length(Y) = m, where [m,n] = size(Z).
■ 8.5.2 Interpolation in Two Dimensionals
6 10 14
12 20 28z
22.5
33.5
4
3
4
5
6
75
10
15
20
25
30
x axis
interp2 example 1
y axis
z ax
is
31 / 7
■ 8.5.2 Interpolation in Two Dimensionals
8.5.2.3 ZI = interp2(Z,XI,YI)
- the data values beiing interpolated are defined on a mesh given by the vectors x=1:n and y=1:m, where [m,n] = size(z); y gives the rows of the grid and x gives the column
- zz = interp2(z’,xx,yy’);
- Example)
x=[1 2 3]
y=[1 2 3 4 5]
z = x’*y z=
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
Xx= [1, 1.2,2,2.2,3]
Yy=[1,1.8,2,4,4.8,5]
Zz = interp2(z’,xx,yy’) =
1.00 1.20 2.00 3.00
1.80 2.16 3.96 5.40
2.00 2.40 4.40 6.00
4.00 4.80 8.80 12.00
4.80 5.76 10.56 14.40
5.00 6.00 11.00 15.00
- mesh(xx,yy,zz)
11.5
22.5
3
1
2
3
4
50
5
10
15
x axis
intep2 example 2
y axis
z ax
is
32 / 7
■ 8.5.2 Interpolation in Two Dimensionals
8.5.2.4 ZI = interp2(X,Y,Z,XI,YI),
- Interpolation on a Rectangular Grid
- Example)
x=[2,4], y =[3,5,7], z= x’y,
xx=[2, 2.4,2.6,2.8,3,3.5,4]
yy = [3,3.5,5,7]
zz= interp2(x,y’,z’,xx,yy’)
>> zz=interp2(x,y,z',xx,yy')
zz =
6.0000 7.2000 7.8000 8.4000 9.0000 10.5000 12.0000
7.0000 8.4000 9.1000 9.8000 10.5000 12.2500 14.0000
10.0000 12.0000 13.0000 14.0000 15.0000 17.5000 20.0000
14.0000 16.8000 18.2000 19.6000 21.0000 24.5000 28.0000
- mesh(xx,yy,zz)
6 10 14
12 20 28z
22.5
33.5
4
3
4
5
6
75
10
15
20
25
30
x axis
interp2 example 3
y axis
z ax
is
33 / 7
■ 8.5.2 Interpolation in Two Dimensionals
8.5.2.5 bilinear interpolation
- The value of an interpolated point is a combination of the values of the four closest points.
- the form of each rectangular subregion
z= a + bx + cy + dxy,
Region Rij, four corners : data values: (xi,yj),(xi,yi+1),(xi+1,yJ),(xi+1,yi+1), four unknowns : aij,bij,cij,dij
z(i,j) = a ij + bij xi + cijyj+dijxiyj
z(i,j+1) = a ij + bij xi + cijyj+1+dijxiyj+1
z(i+1,j) = a ij + bij xi+1 + cijyj+dijxi+1yj
z(i+1,j+1) = a ij + bij xi+1 + cijyj+1+dijxi+1yj+1
- the form of the interpolation methods
: ZI = interp2(X,Y,Z,XI,YI,method), method=> ‘cubic’,nearest’,’linear’
- interp3 : VI = interp3(X,Y,Z,V,XI,YI,ZI) interpolates to find VI, the values of the underlying three-dimensional function V at the points in arrays XI,YI and ZI. 3-dimensional
- interpn : VI = interpn(X1,X2,X3,...,V,Y1,Y2,Y3,...) interpolates to find VI, the values of the underlying multidimensional function V at the points in the arrays Y1, Y2, Y3, etc. n-dimensional