newton_interpol.m

来自「程序包中含有Lagrange插值、Newton插值、Hermite插值、jaco」· M 代码 · 共 23 行

M
23
字号
% Interpolation with Newton  polynomials

% Input: x,y: y=f(x)
%            xt: where interpolant is evaluated.
% Output: yt=f(xt)

function yt =  Newton_interpol(x,y,xt)

n = length(y); if length(x)~=n, error('x and y are not compatible'); end

c=y(:);
for j=2:n
    for i=n:-1:j
        c(i)=( c(i)-c(i-1) )  /  ( x(i) - x(i-j+1) );  % note that x(i)-x(i-1) is not right.
    end
end

% Nested evaluation of the polynomial
yt = c(n);
for i= n-1 :-1 :1
    yt = yt.*(xt - x(i)) + c(i);
end

⌨️ 快捷键说明

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