Qingfeng Mathematical Modeling—Interpolation Algorithm

Interpolation

effect

In digital modeling competitions, it is often necessary to process and analyze data and models based on known function points. However, there may be very little data or missing data. At this time, the data cannot support the analysis. In this case, some mathematics must be used. method to simulate and generate some new but more reliable values ​​to meet the needs of the data. The above mentioned is exactly the role of interpolation method

definition

Assume that the function y=f(x) is defined on the interval [a,b], and it is known that the point
a < = x 0 < x 1 < . . . < xn < = b a<=x_0<x_1<... <x_n<=ba<=x0<x1<...<xn<=The values ​​on b
are:
y 0 , y 1 , . . . < yn y_0,y_1,...<y_ny0,y1,...<yn
If there is a simple function P(x) such that
P ( xi ) = yi ( i = 0 , 1 , 2 , . . . , n ) P(x_i)=y_i (i=0,1,2,... ,n)P(xi)=yi(i=0,1,2,...,n )
, then P(x) is called the interpolation function of f(x), the points x0, x1,..., xnare called interpolation nodes, and the interval [a, b] including the interpolation nodes is called the interpolation interval. Find the interpolation value The method of function P(x) is called interpolation method.

concept

The concepts of three commonly used interpolation methods

  1. Interpolation polynomial. If P(x) is an algebraic polynomial of degree no more than n, that is

P ( x ) = a 0 + a 1 x + . . . + a n x n , P(x)=a_0+a_1x+...+a_nx^n, P(x)=a0+a1x+...+anxn,

  1. If P(x) is a piecewise polynomial, it is called piecewise interpolation.
  2. If P(x) is a trigonometric polynomial, it is called trigonometric interpolation

This article only introduces polynomial interpolation and piecewise interpolation.

One-dimensional interpolation problem

image-20230807212542148

  • Some data x i , yi are known , and these data can simulate an f(x) function (image). Find y * by bringing the new data x * into the f(x) function .

One-dimensional interpolation polynomial principle

theorem

image-20230808110433502

image-20230808110445329

  • It is known that matrix X and matrix Y are both invertible matrices, then AX=Y can be transformed into A=YX - . Then if the determinant of matrix A is not 0, then the system of equations has a unique solution
  • The determinant can be calculated using the Vandermonde determinant method
  • If a system of equations has a unique solution, then the polynomial must uniquely exist

Lagrangian interpolation and Newton interpolation

image-20230808114135919

image-20230808112027598

Red is the objective function, and blue is the function image simulated by Lagrangian interpolation method. It can be seen that as the number of times increases, the images at both ends have obvious oscillations.

  • Lagrangian interpolation is commonly used in polynomial interpolation. However, when this method is used for high-order interpolation, the two ends will fluctuate greatly, resulting in obvious oscillation, which is the Runge phenomenon. Therefore, if you are not familiar with the curve motion trend, do not use high-order interpolation easily. In addition, the function is difficult to use, so polynomial interpolation is rarely used in digital and analog competitions.

image-20230808114246325

  • The Newton interpolation method only needs to add new terms to the original function each time based on the first n terms to generate a new function. Compared with the Lagrangian interpolation method, the calculation process of the Newton interpolation method is inheritable.
  • However, Newton's interpolation method also suffers from Runge's phenomenon.

in conclusion:

  • The higher the degree of the interpolation polynomial, the accuracy may not be significantly improved.
  • The higher the degree of the interpolation polynomial, the intake error may increase significantly.
  • In fact, it is not only required that the interpolating function and the interpolated function have the same function value at all nodes, it also requires that the interpolating polynomial and the interpolated function have the same low-order or even high-order derivative values ​​at one or all nodes. Therefore, this interpolation polynomial cannot fully reflect the behavior of the interpolated function.

Based on the shortcomings of interpolation polynomials, piecewise interpolation is usually used in digital-analog competitions.

Hermitian interpolation

image-20230808114542143

  • The degree of the polynomial obtained by directly using Hermite interpolation is high, and there is also the Runge phenomenon. Therefore, in practical applications, piecewise cubic Hermite interpolation polynomial (PCHIP) is often used.

Piecewise linear interpolation

image-20230808113318767

If the newly inserted value x i is between x j-1 and x j , then you only need to simulate the interpolation function between x j-1 and x j .

Piecewise cubic Hermitian interpolation code

Matlab has built-in functions, and the implementation process has been encapsulated for us. All we need to do is know how to call them.

function prototype

p=pchip(x,new_x)

x is the abscissa of the known sample point; y is the ordinate of the known sample point; new_x is the abscissa of the corresponding point to be inserted, and the ordinate corresponding to new_x is simulated through the pchip function

Assume that the range of x is [-pi,pi]; y=sin(x); new_x=-pi:0.1:pi (an abscissa spaced from -pi to pi is 0.1)

Then you can call it like this

x=-pi:pi;
y=sin(x);
new_x=-pi:0.1:pi;
p=pchip(x,y,new_x);%%p是通过Hermite插值法模拟出来的对应new_x的纵坐标
plot(x,y,'o',new_x,p,'r-');
legend('样本点','三次埃尔米特插值','Location','southeast');

image-20230808122831263

It can be seen that the sample point function corresponds to the o-point diagram, and the function image simulated by the Hermitian interpolation method is the red line

Cubic spline interpolation and its code

image-20230808123117149

  • The matlab built-in function for cubic spline interpolation is

    p = spline (x,y, new_x)
    
  • x is the abscissa of the known sample point; y is the ordinate of the known sample point; new_x is the abscissa of the place to be inserted.

Similarly, the cubic spline interpolation method is used to simulate the image corresponding to new_x.

x=-pi:pi;
y=sin(x);
new_x=-pi:0.1:pi;
p1=pchip(x,y,new_x);%%p是通过Hermite插值法模拟出来的对应new_x的纵坐标
p2=spline(x,y,new_x);
plot(x,y,'r-',new_x,p1,'b.',new_x,p2,'g*');

legend('样本点','三次埃尔米特插值','三次样条插值','Location','southeast');

image-20230808130016365

It can be seen that the curve generated by the cubic spline is smoother. In actual modeling, since we do not know the generation process of the data, both interpolations can be used

example

First, there is the population of China from 2009 to 2018, and the population of China from 2019 to 2023 is predicted through cubic Hermitian interpolation prediction or cubic spline interpolation prediction.

year=2009:2018;
population=[133126,133770,134413,135069,135738,136427,137122,137866,138639, 139538];
p1=pchip(year,population,2019:2023);
p2=spline(year,population,2019:2023);
plot(year,population,'r-',2019:2023,p1,'b.',2019:2023,p2,'g*');
legend('样本点','三次埃尔米特插值预测','三次样条插值预测','Location','SouthEast')

image-20230808132427804

In addition, if you need to make two figures, you need to indicate which figure it is before drawing, otherwise the system will judge that it is only drawing on figure (1), and subsequent images will refresh the previous image.

image-20230808132908820

Interpolation of n-dimensional data (understanding)

function prototype

p=interpn(x1,x2,...,xn,y,new_x1,new_x2,...,new_xn,method)
  • x1,x2,…,xn are the abscissas of the known sample points
  • y is the ordinate of the known sample point
  • new_x1, new_x2,…, new_xn are the abscissa coordinates of the point to be inserted
  • method is the method to be interpolated
    • 'spline': cubic spline interpolation method; (most accurate)
    • 'pchip': Cubic Hermitian interpolation
    • 'linear': linear interpolation (default algorithm)
    • 'cubic': cubic interpolation
    • 'nearest': nearest neighbor interpolation algorithm
x=-pi:pi;
y=sin(x);
new_x=-pi:0.1:pi;
p2=spline(x,y,new_x);

Equivalent to

x=-pi:pi;
y=sin(x);
new_x=-pi:0.1:pi;
p2=interpn(x,y,new_x,'spline');
  • 'nearest': nearest neighbor interpolation algorithm
x=-pi:pi;
y=sin(x);
new_x=-pi:0.1:pi;
p2=spline(x,y,new_x);

Equivalent to

x=-pi:pi;
y=sin(x);
new_x=-pi:0.1:pi;
p2=interpn(x,y,new_x,'spline');

Guess you like

Origin blog.csdn.net/m0_71841506/article/details/132165130