Why is there an error on my plot line?
이전 댓글 표시
I am writing a code that plots Lagrange-Polynomial-Interpolation and the part that's messing up is the plot(X,P,'b');
I have inserted a % to make it a comment and test the rest of the code and the rest of the code works. But when I remove the % from the plot(X,P,'b'); line, an error pops up at this line. What am I doing wrong?
Here's the entire code:
f = @(x) 3*exp(-x)+2*sin(x);
X = 0:3;
Y = f(X);
n = length(X);
P = 0;
syms x;
L = sym(zeros(size(X)));
for i = 1:n
L(i) = 1;
for j = 1:n
if (j ~= i)
L(i) = L(i)*(x-X(j))/(X(i)-X(j));
end
end
P = P + Y(i)*L(i);
end
disp(P)
plot(X,P,'b');
hold on;
grid on;
fplot(f,[0,3],'r');
hold on;
plot(X,Y,'or');
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

