目录
B.Piecewise Linear Interpolation
1.简介
在通常的数据处理时,会遇到现有的数据是极少的,不足以支撑分析的进行,或者数据出现错误或者明显不符合,这时就需要使用一些数学的方法,“模拟产生”一些新的但又比较靠谱的值来满 足需求,这就是插值的作用。
2.模型
(1)一维插值
概念
下图阐述了一般的插值法的概念与类别[1]:
A.Lagrange Interpolation
在次数较低的时候,插值较为精准,但是随着次数上升,会出现Runge现象。高次插值会产生龙格现象,即在两端处波动极大,产生明显的震荡。在不熟悉曲线 运动趋势的前提下,不要轻易使用高次插值。
Runge phenomenon:
B.Piecewise Linear Interpolation
插值多项式次数过高可能精度提升不明显,摄入误差可能显著增加。因此,考虑分段插值。
C.Newton Interpolation
差商定义:
一阶差商:
二阶差商:
k 阶差商:
对比 Newton Interpolation 和 Lagrange Interpolation:
与拉格朗日插值法相比,牛顿插值法具有继承性(牛顿插值法每次插值只和前n项的值有关,每次只要在原函数上添加新的项,就可产生新的函数)。但是两者均存在龙格现象的 问题。
上述两种插值仅要求插值多项式在插值节点处与被插函数有相等的函数值,而这种插值多项式却不能全面反映被插值函数的性态。
D. Hermite Interpolation
一般插值要求:
更高的要求:
这个要求的本质是是曲线在节点曲度一致,光滑切合。
具体原理参考[1]:
由于直接使用存在较高次的项,会出现龙格现象,实际使用的是分段三次Hermite Interpolation(PCHIP)。在Matlab里面由直接封装好的函数 pchip。
E.Cubic Spline Interpolation
具体定义见下图:
在Matlab中有封装好的函数 spline。
效果如下:
具体使用哪个可以根据实际效果来选择。
(2)n维插值
基本原理与上述的一维一致,只是将变量数目拓展到n维,Matlab中函数如下:
注:在某种意义上,插值可以做简单的短期预测,但是局限性较大,不很推荐,建议使用灰色预测之类预测算法。
3.代码
%% pchip and spline
x = -pi:pi;
y = sin(x);
new_x = -pi:0.1:pi;
p1 = pchip(x,y,new_x);
p2 = spline(x,y,new_x);
figure(1);
plot(x,y,'o',new_x,p1,'r-.',new_x,p2,'b--')
legend('sample','pchip','spline','Location','SouthEast')
%% n dim data interpolation
x = -pi:pi; y = sin(x);
new_x = -pi:0.1:pi;
p = interpn (x, y, new_x, 'spline');
% Equivalent to p = spline(x, y, new_x);
figure(2);
plot(x, y, 'o', new_x, p, 'r-')
%& simple prediction(usually use this method)
population=[133126,133770,134413,135069,135738,136427,137122,137866,138639, 139538];
year = 2009:2018;
p1 = pchip(year, population, 2019:2021);
p2 = spline(year, population, 2019:2021);
figure(3);
plot(year, population,'o',2019:2021,p1,'r*-',2019:2021,p2,'bx-')
legend('sample','pchip','spline','Location','SouthEast')
4.REFERENCE
[1]刘春凤: 中国大学MOOC数值计算方法