I have a code for the Lagrange polynomial but I have an error and I do not know how to solve it.
function polLagrange(xk,yk)
x = min(xk)-0.5:0.1:max(xk)+0.5;
n = length(xk);
m = length(yk);
p = zeros(1,n);
for i = 1:n
suma = 0;
%display(x(i));
for k = 1:m
suma = suma + (lagrangiano(xk,k)*yk(k));
end
p(i) = suma;
%display(p);
end
%display(p);
plot(xk,yk,'*');
grid on;
hold on;
plot(x,p);
end
The error that appears to me is:
In an assignment A (:) = B, the number of elements in A and B must be the same.
Error in polLagrange (line 12) p (i) = sum;