Lagrange Interpolation related problem (plotting a graph)

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!

Respuestas (1)

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 comentarios

Error using gobjects (line 42)
Not enough input arguments.
Error in newplot (line 47)
fig = gobjects(0);
Error in Untitled3 (line 13)
plot(x, L(i,:)), hold all
This error is shown!!
The number of values entered for x and y are equal or not?
Make sure that they have equal number of value entries via input().
They are
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;

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Preguntada:

el 29 de Mayo de 2021

Comentada:

el 30 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by