l2.m

来自「fit programme for a serials of data」· M 代码 · 共 42 行

M
42
字号
function X=L2(x,y,x1)
% input x is a vector that contains a list of abscissas
%       y is a vector that cntains a list of ordinates
%       x1 is the number at where the interpolation is to be obained
% output X is the parabola interpolation at x1
n=length(x);
j=-1;
for i=1:n-1
    if x1<x(i+1)&&x1>x(i)
       j=i;
       break;
    end
end
if j==-1
   'false';
   return;
end
if j==n-1
   i=j;
else 
    if j==1
       i=j+1;
    else
        e1=abs(x1-x(j-1));
        e2=abs(x1-x(j+2));
        if e1>e2
           i=j;
        else
          i=j+1;
        end
    end
end
X=0;
for j=i-1:i+1
    c=1;
    for k=i-1:i+1
        if k~=j
           c=c*(x1-x(k))/(x(j)-x(k));
        end
    end
    X=X+y(j)*c;    
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?