求Lagrange插值多项式
syms x;
X = [1, 3/2, 0, 2]
Y = [3, 13/4, 3, 5/3]
n = length(X);
L = sym('1');
P = sym('0');
for i = 1:n
% 求出 Li(x)
Li = sym('1');
for j = 1:n
if j~=i
Li = Li*(x-X(j))/(X(i)-X(j));
end
end
% 更新插值多项式 P(x)
P = P + Y(i)*Li;
end
disp('拉格朗日插值多项式为:');
pretty(simplify(P)); % pretty函数使输出更易读
标签:end,笔记,插值,多项式,sym,Li,matlab,杂乱
From: https://www.cnblogs.com/code-pigeon/p/17803962.html