Lagrange Interpolation related problem (plotting a graph)

조회 수: 3 (최근 30일)
Maha Aftab
Maha Aftab 2021년 5월 29일
댓글: Sulaymon Eshkabilov 2021년 5월 30일
x = input('Enter values of x: ');
y = input('Enter values of y: ');
n = length(x);
L = zeros(n,n);
for i = 1:n
V= 1;
for j = 1:n
if i~= j
V = conv(V,poly(x(j)))/(x(i) - x(j));
end
end
L(i,:) = V*y(i);
end
L
P = sum(L)
Now here I want to plot the graph of a certain method, But don't know how to do it!

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 5월 29일
Hi
The answer is simple:
plot(x, L(1,:)) OR plot(x, L(2,:))
plot(x, V) or plot(x, P)
Or within the loop:
...
if i~= j
V = conv(V,poly(x(j)))/(x(i) - x(j));
end
end
L(i,:) = V*y(i);
plot(x, L(i,:)), hold all
end
  댓글 수: 4
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 5월 30일
Test again:
x = input('Enter values of x: ');
y = input('Enter values of y: ');
n = length(x);
L = zeros(n,n);
for i = 1:n
V= 1;
for j = 1:n
if i~= j
V = conv(V,poly(x(j)))/(x(i) - x(j));
end
end
L(i,:) = V*y(i);
plot(x, L(i,:)), hold all
end
x = linspace(0, 5);
y = linspace(0, 5)*2+linspace(0, 5).^2;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by