100% found this document useful (1 vote)
230 views1 page

Periodic Spline

This function performs cubic spline interpolation with periodic boundary conditions on input data to generate outputs at specified points. It takes in knots (x), values at knots (y), and output points (xx). It sets up and solves a tridiagonal system of equations to determine the spline coefficients, then uses those coefficients to calculate the interpolated values (yy) at points xx using cubic polynomials on each segment between knots.

Uploaded by

andrepriob
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
230 views1 page

Periodic Spline

This function performs cubic spline interpolation with periodic boundary conditions on input data to generate outputs at specified points. It takes in knots (x), values at knots (y), and output points (xx). It sets up and solves a tridiagonal system of equations to determine the spline coefficients, then uses those coefficients to calculate the interpolated values (yy) at points xx using cubic polynomials on each segment between knots.

Uploaded by

andrepriob
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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