1.拉格朗日逼近
function [C,L]=lagran(X,Y) % X为横坐标 % Y为纵坐标 % L为拉格朗日多项式系数 % C=L*Y为构造的拉格朗日多项式的解C=L1*Y1+......Ln*Yn w=length(X); n=w-1; L=zeros(w,w); % 构造拉格朗日迭代 for k=1:n+1 V=1; for j=1:n+1 if k~=j V=conv(V,poly(X(j)))/(X(k)-X(j)); %poly(X(j)=X-X(j),故conv(V,poly(X(j)))=(X-X1)*....*(X-Xn+1) end end L(k,:)=V; end C=Y*L;