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
%x1=[1,2,5,6,7,8,10,13,17]
%y1=[3,3.7,3.9,4.2,5.7,6.6,7.1,6.7,4.5]
%x2=[17,20,23,24,25,27,27.7]
%y2=[4.5,7,6.1,5.6,5.8,5.2,4.1]
%x3=[27.7,28,29,30]
%y3=[4.1,4.3,4.1,3]
***************************
function [s]=Spline(x,y,x0)
n=length(x);
for i=1:n-1
h(i)=x(i+1)-x(i);
end
%disp(h);
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
%disp(A);
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));
end
k=1;
for i=1:n-1
if(x0=x(i))
k=i;
end
end
if(x0>=x(n-1))
k=n-1;
end
end
No hay comentarios:
Publicar un comentario