1,拉格朗日插值公式:
先定义数据如下:
x | 0 | 1 | 2 | 3 |
y | -5 | -6 | -1 | 16 |
公式推导如下:定义公式:
2,本例推导:
3,插值代码实现,ployinterp.m
function v = ployinterp(x,y,u)
n = length(x);
v = zeros(size(u));
for k = 1:n
w = ones(size(u));
for j = [ 1: k-1 k+1:n]
w = (u-x(j)) ./ (x(k)-x(j)).*w;
end
v=v+w*y(k);
end
4,代码运行以及结果显示: