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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by