divdifftable.m
来自「数值方法和MATLAB实现与应用.zip」· M 代码 · 共 21 行
M
21 行
function D = divDiffTable(x,y)
% divdiffTable Construct a table of divided-difference coefficients
%
% Synopsis: D = divDiffTable(x,y)
%
% Input: x,y = vectors containing the tabulated y = f(x) data
%
% Output: D = matrix containing divided-difference coefficients in
% its lower triangle. Diagonal entries are coefficients
% of the Newton polynomial
n = length(y);
if length(x)~=n, error('x and y are not compatible'); end
D = zeros(n,n);
D(:,1) = y(:); % First column is zeroth order difference, f[x_i] = y_i
for j=2:n
for i=j:n
D(i,j) = (D(i,j-1)-D(i-1,j-1))/(x(i)-x(i-j+1));
end
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?