Newton polynomial interpolating points, matrix too big

2 ビュー (過去 30 日間)
am
am 2019 年 5 月 23 日
コメント済み: darova 2019 年 5 月 26 日
Hi,
My code to make a newton polynomial and plot it does not work. I cannot figure out what the problem is. "Matrix dimensions must agree". It seems my matrix A grows too much.
f = @(x) x.^2.*sin(x);
x = [0 1 2 3 5 7 8];
y= f(x);
k = length(x)
ak=ones(k,1);
A = ak;
for column=2:k
ak = ak.*(x-x(column-1));
A =[A ak];
end
c=A\y
p =@(x) c(1) + c(2)*x + c(3)*x.^2+c(4)*x.^3;
tv = 0:0.1:6;
plot(tv, p(tv), 'r')
hold on;
plot(tv, f(tv), 'b')

採用された回答

Alex Mcaulley
Alex Mcaulley 2019 年 5 月 23 日
Try changing this line
c=A\y
by
c=A\y'
  10 件のコメント
am
am 2019 年 5 月 26 日
Thank you very much for this thorough answer.
darova
darova 2019 年 5 月 26 日

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by