Newton polynomial interpolating points, matrix too big

2 vues (au cours des 30 derniers jours)
am
am le 23 Mai 2019
Commenté : darova le 26 Mai 2019
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')

Réponse acceptée

Alex Mcaulley
Alex Mcaulley le 23 Mai 2019
Try changing this line
c=A\y
by
c=A\y'
  10 commentaires
am
am le 26 Mai 2019
Thank you very much for this thorough answer.
darova
darova le 26 Mai 2019

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by