viernes, 11 de noviembre de 2011

SNOOPY CON SPLINE








EL CODIGO DEL PROGRAMA

function [s]=Spline(x,y,x0)

n=length(x);

for i=1:n-1

h(i)=x(i+1)-x(i);

end

A(1,1)=1;

A(n,n)=1;

for i=2:n-1
A(i,i-1)=h(i-1);
A(i,i)=2*(h(i-1)+h(i));
A(i,i+1)=h(i);
end
B(1)=0;
B(n)=0;
for i=1:n-2
B(i+1)=(3/h(i+1))*(y(i+2)-y(i+1))-(3/h(i))*(y(i+1)-y(i));
end
c=inv(A)*B';
for i=1:n-1
b(i)=(1/h(i))*(y(i+1)-y(i))-(h(i)/3)*(2*c(i)+c(i+1));
d(i)=(c(i+1)-c(i))/(3*h(i));endk=1;
for i=1:n-1
if(x0=x(i))
k=i; endendif(x0>=x(n-1))
k=n-1;ends=y(k)+b(k)*(x0-x(k))+c(k)*(x0-x(k))^2+d(k)*(x0-x(k))^3;
end



function Grafico(x,y,a,b)
h=a:b;
n=length(h);
for i=1:n
j(i)=ejemplo(x,y,a);
a=a+1;
end
plot(h,j);


end

No hay comentarios:

Publicar un comentario