Newton polynomial interpolating points, matrix too big

2 visualizaciones (últimos 30 días)
am
am el 23 de Mayo de 2019
Comentada: darova el 26 de Mayo de 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')

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by