function [ f, p ] = SymSpline( m, t )
% SymSpline gives the analytical form of B-spline of order m with knots in partition t
%
% Usage:    [ f, p ] = SymSpline( m, t );
%           [ f, p ] = SymSpline( m );
%   
% Inputs: 
%   m       order of spline (m>=1), m=1 is a piecewise constant function       
%   t       sequence of knots (optional) 
%           if t is a single number then the sequence is considered to be t:t+m
%           if t not specified, t=0:m
%
% Outputs:
%   f       array of m symbolical polynomials, each polynomial describes the desired
%           B-spline on the subinterval [t(i),t(i+1)], i=1,...,m  
%   p       matrix of coefficients for polynomials expressed in f, 
%           each row in this matrix represents a_{m-1}, ..., a_0 for
%           polynomials written as a_{m-1}x^{m-1}+...+ a_0
%  
% Remark:   If length of t is bigger than m+1, this procedure takes in account
%           only first m+1 knots of t
%
% References: 
%   L.L. Schumaker, Spline Functions: Basic Theory, New York, Wiley, 1981.  

% See http://www.ncrg.aston.ac.uk/Projects/BiOrthog/ for more details  

%initilization of output variables  
f=sym('','real');  
p=zeros(m,m);

% if t not specified, default knot sequence is 0:m
if nargin==1 t=0:m;end; 

% if specified only the first knot
if length(t)==1 t=t:t+m;end

% test of length of t
if length(t)<1+m error('Too short knot sequence!');end

%calculation of analytical form
for i=1:m
  f(i)=BSpline(m,1,i,t);
  f(i)=simplify(f(i));
  p(i,:)=sym2poly(f(i));
end


%Copyright (C) 2006 Miroslav ANDRLE and Laura REBOLLO-NEIRA
%
%This program is free software; you can redistribute it and/or modify it under the terms 
%of the GNU General Public License as published by the Free Software Foundation; either 
%version 2 of the License, or (at your option) any later version.
%
%This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
%without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%See the GNU General Public License for more details.
%
%You should have received a copy of the GNU General Public License along with this program;
%if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
%Boston, MA  02110-1301, USA.
