function Lagrange(x,y,xk)
n=length(x);
pol1(1)=1;
for i=1:n
p1=1;
p2=1;
for j=1:n
if(j~=i)
p1=p1*(xk-x(j));
p2=p2*(x(i)-x(j));
end
end
d(i)=y(i)/p2;
l(i)=p1/p2;
end
c(1)=1;
for i=1:n
z=length(c);
for j=1:n
if(j~=i)
pol1(2)=-x(j);
c=conv(c,pol1);
end
end
for a=1:length(c)
m(i,a)=c(a);
end
c=ones(z);
end
for i=1:length(m)
for j=1:n
m(j,i)=m(j,i)*d(j);
end
end
for i=1:length(m)
s=0;
for j=1:n
s=s+m(j,i);
end
r(i)=s;
end
p=0;
for i=1:n
p=p+l(i)*y(i);
end
s=0;
n=length(r);
for i=1:n
s=s+r(i)*(xk^(n-i));
end
disp 'EL RESULTADO ES:';
disp(r);
disp(s);
EL RESULTADO ES:
0 1 0 0
6.7600
No hay comentarios:
Publicar un comentario