我需要使用多项式插值来插值函数,但我不确定如何编写部件来获取多项式及其系数:

enter image description here

我的功能:

fx = @(x) sin(3 .*x) ./ (0.4 .+ (x .-2) .^2);

我的9个样本值:

xs = 0:0.5:4;
ys = fx(xs);

My attempt:

n = 2;
x(1) = xs; # not sure if this is correct

for k=1:n-1

    for j=k+1:n

        p = ((x(1) - x(j)) / x(1) - x(j))* fx(x(j));
    endfor

endfor

但我觉得很失落,我不太明白 . 有人可以帮帮我吗?