Presentation is loading. Please wait.

Presentation is loading. Please wait.

2005. 05. 11 2003010482 Mohiuddin Ahmad 2005010207 SUNG-BONG JANG Interpolation II (8.4 SPLINE INTERPOLATION) (8.5 MATLAB’s INTERPOLATION Functions)

Similar presentations


Presentation on theme: "2005. 05. 11 2003010482 Mohiuddin Ahmad 2005010207 SUNG-BONG JANG Interpolation II (8.4 SPLINE INTERPOLATION) (8.5 MATLAB’s INTERPOLATION Functions)"— Presentation transcript:

1 2005. 05. 11 2003010482 Mohiuddin Ahmad 2005010207 SUNG-BONG JANG Interpolation II (8.4 SPLINE INTERPOLATION) (8.5 MATLAB’s INTERPOLATION Functions)

2 Computer Vision and Pattern Recognition Lab. Mohiuddin Ahmad (mohi@image.korea.ac.kr)mohi@image.korea.ac.kr ID: 2003010482 Computer Vision and Pattern Recognition Lab. Dept. of Computer Science and Engineering Korea University 8.4 : Spline Interpolation

3 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

4 Computer Vision and Pattern Recognition Lab. Spline Interpolation Piecewise Linear Interpolation  Simplest form of piecewise polynomial interpolation  Interpolate the data with piecewise linear function

5 Computer Vision and Pattern Recognition Lab. Piecewise Linear Interpolation Example 8.14 Piecewise Linear Interpolation Function is continuous, but not smooth Figure 8.18 Piecewise linear interpolation

6 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:

7 Computer Vision and Pattern Recognition Lab. Piecewise Quadratic Interpolation We define Since, Equations at the interior nodes [impose continuity condition on the polynomials]

8 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  (a 1, a 2, a 3, a 4, b 1, b 2, b 3, b 4 ) Equations for the coefficients at the zero slope conditions at the end points of the interval

9 Computer Vision and Pattern Recognition Lab. Piecewise Quadratic Interpolation – Example Example : 8: 15 Piecewise interpolating polynomial

10 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)

11 Computer Vision and Pattern Recognition Lab. Piecewise Cubic Interpolation Cubic spline function S(x), n-cubic polynomials P i (x) with coefficients p i,0, p i,1, p i,2, and p i,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 [x 0, x n-1 ]..

12 Computer Vision and Pattern Recognition Lab. Piecewise Cubic Interpolation Use S // (x i )=a i-1, S // (x i+1 )=a i and h i =x i+1 – x i, we get, Integrating twice will introduce two constant of integration, and the cubic function is From, definition of h i, Integrating P // i (x) twice and using P i (x i ) =y i & P i (x i+1 ) =y i+1 :  Determine the value of b i and c i.

13 Computer Vision and Pattern Recognition Lab. Piecewise Cubic Interpolation Construction of cubic spline  From property IV, 1 st derivative of P i and P i+1 must agree at x i+1 Natural cubic spline assigns,  2 nd 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) | < kh 4 G =O(h 4 )

14 Computer Vision and Pattern Recognition Lab. Choice of Two Additional Conditions End point constraints for a cubic spline Description of the strategyEquation involving a 0 and a n (i) Clamped cubic spline: specify S / (x 0 ), S / (x n ) (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

15 Computer Vision and Pattern Recognition Lab. Example 8.16 Natural Cubic Spline Interpolation Example 8:16

16 Computer Vision and Pattern Recognition Lab. Example 8.16 Natural Cubic Spline Interpolation Example 8:16 – cont’d

17 Computer Vision and Pattern Recognition Lab. Matlab function for Natural Cubic Spline Matlab code

18 Computer Vision and Pattern Recognition Lab. Matlab function for Natural Cubic Spline

19 Computer Vision and Pattern Recognition Lab. Example 8.17 Runge Function 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

20 Computer Vision and Pattern Recognition Lab. Example 8.17 Runge Function 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

21 Computer Vision and Pattern Recognition Lab. Example 8.17 Runge Function Cubic spline simplifies p1 = 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 ;

22 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]

23 Computer Vision and Pattern Recognition Lab. Example: 8.19 Difficult data Data points: Tridiagonal system of equations: 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 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

24 Computer Vision and Pattern Recognition Lab. Example: 8.19 Difficult data – cont’d Resulting piecewise function made the following polynomial

25 2005. 05. 11 2005010207 SUNG-BONG JANG Interpolation II (8.5,MATLAB’s INTERPOLATION Functions)

26 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)

27 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)

28 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.nonincreasingnondecreasing A function is monotonic if its first derivative (which need not be continuous) does notderivative change sign. - the data that are not uniformly spaced : interp1q. - MATLAB ‘plot’ function : linear interpolation

29 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 30 / 7 8.5.2.2 ZI = interp2(Z,ntimes) - expands the data matrix z by interleaving interpolanes between every element. xx = [x 1, (x 2 + x 2 )/2, x 2,….,(x n-1 + x n-1 )/2, x n ] yy = [y 1, (y 2 + y 2 )/2, y 2,….,(y n-1 + y n-1 )/2, y n ] - 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

31 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= Xx= [1, 1.2,2,2.2,3] Yy=[1,1.8,2,4,4.8,5] Zz = interp2(z ’,xx,yy ’ ) = - mesh(xx,yy,zz)

32 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)

33 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: (x i,y j ),(x i,y i+1 ),(x i+1,y J ),(x i+1,y i+1 ), four unknowns : a ij,b ij,c ij,d ij z(i,j) = a ij + b ij x i + c ij y j +d ij x i y j z(i,j+1) = a ij + b ij x i + c ij y j+1 +d ij x i y j+1 z(i+1,j) = a ij + b ij x i+1 + c ij y j +d ij x i+1 y j z(i+1,j+1) = a ij + b ij x i+1 + c ij y j+1 +d ij x i+1 y j+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


Download ppt "2005. 05. 11 2003010482 Mohiuddin Ahmad 2005010207 SUNG-BONG JANG Interpolation II (8.4 SPLINE INTERPOLATION) (8.5 MATLAB’s INTERPOLATION Functions)"

Similar presentations


Ads by Google