自写程序,拉格朗日插值且给出插值多项式的系数
有时候只是想知道 拉格朗日插值 后的多项式系数具体是多少,这个程序就能实现!function coef=LagrangeInterpolation(xx,yy)
%get the ploynimial coefficients of Lagrange interpolation.
%input is a set of sample points
%output is the coefficients of Lagrange interpolation.
syms x
y=0;
%start to implement the Lagrange interpolation
for i=1:length(xx)
p=1;
for j=1:length(xx)
if(j~=i)
p=p*(xx(j)-x)/(xx(j)-xx(i));
end
end
y=y+p*yy(i);
end
%get the coefficients of polynimial
coef=sym2poly(y);
return
页:
[1]