newtonpol.m

来自「小的源码Matlab编程」· M 代码 · 共 30 行

M
30
字号


function [yi, a] = Newtonpol(x, y, xi)

% Values yi of the interpolating polynomial at the points xi.
% Coordinates of the points of interpolation are stored in 
% vectors x and y. Horner's method is used to evaluate 
% a polynomial. Second output parameter a holds coefficients
% of the interpolating polynomial in Newton's form.

a = divdiff(x, y);
n = length(a);
val = a(n);                  
for m = n-1:-1:1
   val = (xi - x(m)).*val + a(m);
end
yi = val(:);


function a = divdiff(x, y)

% Divided differences based on points stored in vectors x and y.
% This is a subfunction.

n = length(x);
for k=1:n-1
   y(k+1:n) = (y(k+1:n) - y(k))./(x(k + 1:n) - x(k));
end
a = y(:);

⌨️ 快捷键说明

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