hermiteint.m

来自「Interpolation routines in matlab」· M 代码 · 共 70 行

M
70
字号
%% Compute Hermite interpolation polynomial.%% function [a] = HermiteInt( x, f )%% input:%        x:     vector containing the %               interpolation points%        f:     vector containing the values %               to be interpolated%% output:%        a:     vector of coefficients of Newton's %               interpolating polynomial%%function [a] = HermiteInt( x, f );N = size(x(:),1);if size(f(:),1) ~= N    ifail = 1;   returnendA = zeros(N,N);%  Compute first column of divided difference tablez      = x(1);A(1,1) = f(1); i1     = 1;             %  New interpolation point appears first at index i1 for j = 2:N    if ( z == x(j) )       A(j,1) = f(i1);    end    if ( z ~= x(j) )        z      = x(j);   % New interpolation point       i1     = j;       A(j,1) = f(i1);     endend  %  Compute remaining columns of the divided differences tablefac = 1;for j = 2:N    fac = fac * (j-1);   % fac = (j-1)!    i1  = j;             % first time equal nodes are detected    for i = j:N        if ( x(i) == x(i-j+1) )             A(i,j) = f(i1) / fac ;        end        if ( x(i) ~= x(i-j+1) )             i1 = i+1;             A(i,j) = ( A(i,j-1) - A(i-1,j-1) ) / (x(i) - x(i-j+1)) ;        end    endendfor j = 1:N    a(j) = A(j,j);endA

⌨️ 快捷键说明

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