You are on page 1of 1

function [C]=lagran(x,y)

x=input('Ingrese Los valores de x [x0 ...xf] : ');


y=input('Ingrese Los valores de y [y0 ...yf] : ');
n1=length(x);
n=n1-1;
L=zeros(n1,n1);
for k=1:n+1
V=1;
for j=1:n+1
if k~=j
V=conv(V,poly(x(j)))/(x(k)-x(j));
end
end
L(k,:)=V
end
C=y*L;
text = '';
exp = length(C);
for r=1: length(C)
exp = exp - 1;
text = strcat(text, '+', num2str(C(r)), '*x.^', num2str(exp));
end
f = inline(text);

syms x;
ezplot(f);
grid on;
end

You might also like