Newton polynomial interpolating points, matrix too big

1 Ansicht (letzte 30 Tage)
am
am am 23 Mai 2019
Kommentiert: darova am 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')

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by