newtintpol.m

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

M
48
字号
%% Compute Newton's interpolating polynomial%% function [a] = NewtIntPol( x, f, iprint )%% input:%        x:     vector containing the %               interpolation points%        f:     vector containing the values %               to be interpolated%   iprint:     print flag%               iprint = 0   no printout%               iprint > 0   print divided difference table%% output:%        a:     vector of coefficients of Newton's %               interpolating polynomial%%function [a] = NewtIntPol( x, f, iprint );n = size(x(:),1);if size(f(:),1) ~= n    ifail = 1;   returnendA = zeros(n,n);A(1:n,1) = f(:);a(1)   = A(1,1);for j = 2:n    for i = j:n        A(i,j) =  ( A(i,j-1) - A(i-1,j-1) ) / (x(i) - x(i-j+1)) ;    end    a(j) = A(j,j);endif( iprint > 0 )    disp('        x         f  ')    disp([x(:) A ])end

⌨️ 快捷键说明

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