Help plotting interpolation ploynomial.

1 回表示 (過去 30 日間)
Yuval
Yuval 2013 年 11 月 1 日
コメント済み: Matt J 2021 年 3 月 21 日
Hi, I was asked to plot psi_n(x) = (x-x_0)(x-x_1)...(x-x_n) for n = 3,7,10,17 evenly distributed nodes in [-5,5] with resolution 0.01. Below is my code:
x=-5:0.01:5;
n=[3 7 10 17];
for j=1:4
node=-5;
psi=1;
while (node <= 5)
psi=psi.*(x-node);
node=node + 10/n(j);
end
subplot(2,2,j);
plot(psi)
hold on
end
Which doesn't quite yield the desired output. Or does it? In any case, it doesn't seem to match what I am getting via using Wolfram. My question is why and, of course, how may I correct it? I'd sincerely appreciate your assistance. Thanks in advance!
  2 件のコメント
Simon
Simon 2013 年 11 月 1 日
Hi!
What is x_0, x_1, ...?
Yuval
Yuval 2013 年 11 月 1 日
The nodes. x_0 is x index zero.

サインインしてコメントする。

回答 (1 件)

Matt J
Matt J 2013 年 11 月 1 日
編集済み: Matt J 2013 年 11 月 1 日
node=linspace(-5,5,n);
p=poly(node);
f=@(z) polyval(p,z);
x=-5:0.01:5;
plot(x,f(x));
  4 件のコメント
Victor McNstein
Victor McNstein 2021 年 3 月 20 日
Hello Matt. How does on combine your code with Yuval's initial work, for better results?
Matt J
Matt J 2021 年 3 月 21 日
I do not see what Yuval thought was incomplete about my code. I think my code already fulfills the entire task.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by