Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

function yy=periodSpl(x,y,xx)

%
%
%
%
%
%
%
%

Cubic spline interpolation with periodic boundary conditions


(useful for parametric spline curves)
x is a vector containing the knots
y is a vector of length same as x containing the values
of the curve at the knots
xx is a "dense" partition of the knot vector
yy is the desired output, i.e. the values of the spline curve
at the points of xx

lenxx=length(xx);
yy=zeros(1,lenxx);
m=length(x);
A=zeros(m,m); q=zeros(m,1);
B=zeros(m,1);
A(1,1:2)=[-2/3,-1/6]; A(1,m-1)=-1/6;
A(m,2)=-1/6; A(m,m-1:m)=[-1/6,-2/3];
Dy2=y(2)-y(1);
Dym=y(m)-y(m-1);
B(1,1)=Dym-Dy2; B(m,1)=B(1,1);
for ii=2:m-1
A(ii,ii-1:ii+1)=[1/6,2/3,1/6];
Dy1=Dy2;
Dy2=y(ii+1)-y(ii);
B(ii,1)=Dy2-Dy1;
end
q=A\B;
yy(1)=y(1);
temp=1;
for ii=2:m
p=length(xx(xx>x(ii-1) & xx<=x(ii)));
t=linspace(0,1,p+1);
yy(temp:temp+p)=(1/6)*q(ii-1)*(1-t).^3+(1/6)*q(ii)*(t.^3)+t*((1/6)*(q(ii-1)q(ii))+(y(ii)-y(ii-1)))+y(ii-1)-(1/6)*q(ii-1);
temp=temp+p;
end

You might also like