Interpolation method
The interpolation method, also known as "interpolation method", is the function of the function f (x) in a certain interval known points, make appropriate specific functions, at other points in the interval with the value of this particular function as the approximate value of function f (x), this method is called interpolation method. If this particular function is a polynomial, it is called an interpolation polynomial.
linear interpolation method
Linear interpolation is the method of determining the value of an unknown quantity between these two known quantities using a line connecting two known quantities.
Suppose we know the coordinates (X0,Y0) and (x1,y1), we want to get the value of X on the line in the [x0,x1] interval. As shown in the figure, we get the two-point linear equation:
Assuming that the values on either side of the equation are alpha, then this value is the interpolation factor-the ratio of distance from x0 to X to the distance from x0 to X1. Since the x value is known, the value of α can be obtained from the formula:
Same:
In this way, it can be expressed in algebra as:
y = (1−α) y0 +αy1
Or
y = y0 + α (y1−y0)
This allows you to get Y directly through Alpha. In fact, even if X is not between x0 and X1 and α is not between 0 and 1, this formula is also true. In this case, this method is called linear extrapolation-see extrapolation values.
The procedure known as Y for X is the same as above, except that X and Y are exchanged. use in MATLAB
%{
the interpolation function in MATLAB is INTERP1, its invocation format is: yi= interp1 (X,y,xi, ' method ')
where x, Y is an interpolation point, Yi is the interpolation result at the interpolated Point Xi; x, y is a vector,
' method ' means the interpolation method used, MATLAB provides a number of interpolation methods:
' nearest ' is the nearest interpolation, ' linear ' linear interpolation, ' spline ' three times spline interpolation; ' pchip ' cubic interpolation value. Linear interpolation is indicated by default
: All interpolation methods require X to be monotonic, and Xi cannot exceed the range of X.
%}
x = 0:2*pi;
y = sin (x);
xx = 0:0.5:2*pi;
% INTERP1 piecewise linear interpolation of the sin function, when called INTERP1, the default is piecewise linear interpolation
y1 = Interp1 (x,y,xx, ' linear ');
Subplot (2,2,1);
Plot (x, y, ' o ', xx,y1, ' R ')
title (' piecewise linear interpolation ')
% near interpolation
y2 = Interp1 (x,y,xx, ' nearest ');
Subplot (2,2,2);
Plot (x, y, ' o ', Xx,y2, ' R ');
Title (' near interpolation ')
% spherical linear interpolation
y3 = INTERP1 (x,y,xx, ' spline ');
Subplot (2,2,3);
Plot (x, y, ' o ', Xx,y3, ' R ')
title (' spherical interpolation ')
% three polynomial interpolation method
Y4 = INTERP1 (x,y,xx, ' pchip ');
Subplot (2,2,4);
Plot (x, y, ' o ', Xx,y4, ' R ');
Title (' Three-time polynomial interpolation ')
An example
%{
the interpolation function in MATLAB is INTERP1, its invocation format is: yi= interp1 (X,y,xi, ' method ')
where x, Y is an interpolation point, Yi is the interpolation result at the interpolated Point Xi; x, y is a vector,
' method ' means the interpolation method used, MATLAB provides a number of interpolation methods:
' nearest ' is the nearest interpolation, ' linear ' linear interpolation, ' spline ' three times spline interpolation; ' pchip ' cubic interpolation value. Linear interpolation is indicated by default
: All interpolation methods require X to be monotonic, and Xi cannot exceed the range of X.
%}
%{
For example: Within 24 hours of the day, the ambient temperature data measured at 2 hours per interval from 0 o'clock, respectively, are
12,9,9,1,0,18, 24,28,27,25,20,18,15,13, and
the temperature at 12 o'clock noon (that is, 13 points).
%}
x = 0:2:24;
y = [ 9 9 ( ) ( );
A =;
Y1 = INTERP1 (x,y,a, ' spline ')
% result: 27.8725
% to get a temperature curve of 24 hours a day, then:
XI = 0:1/3600:24;
The% interpolation point can be a vector, then return the corresponding vector
Yi = interp1 (x,y,xi, ' spline ');
Plot (x, y, ' o ', xi,yi);