%       get needed subroutines:
%
misc_sinc


%%============================================================================= 
%%       Form collocation matrix for u+u', using sinc basis only:
%%============================================================================= 
% 
ind = [-10:10]; 
xval = xk(ind,h)';
mat = skh(-10,h,xval) + skh_p(-10,h,xval);
for i=-9:10,            % k ranges from -10 to 10
  mat = [mat skh_p(i,h,xval)+skh(i,h,xval)];
endfor

sv1 = svd(mat)          %% rank deficient by one; otherwise nice

% equilibrate
col = 1./max(abs(mat));
smat = mat*diag(col);
row = 1./max(abs(smat'));
smat = diag(row)*smat;
 
sv2 = svd(smat)         %% little change



%%============================================================================= 
%%       Form collocation matrix for u'' on the interior
%%============================================================================= 
% 
%----------- interior points, sincs:
ind = [-10:10]; 
xval = xk(ind,h)';
mat1 =  skh_pp(-10,h,xval);
for i=-9:10,            % k ranges from -10 to 10
  mat1 = [mat1 skh_pp(i,h,xval)];
endfor
mat = mat1;

sv1 = svd(mat)          %% nasty tendency, poor conditioning

col = 1./max(abs(mat));
smat = mat*diag(col);
row = 1./max(abs(smat'));
smat = diag(row)*smat;
 
sv2 = svd(smat)         %% same creeping sigmas, but conditioning
                        %% within expected bounds (1080.2)

%%============================================================================= 
%%       Form collocation matrix for u'' on the interior, u on the right
%%       boundary using sinc basis/ right value  spline only 
%%============================================================================= 
% 
%       use 21 sinc terms, and 1 spline ==> need 22 points total, 21 interior
%----------- interior points, sincs:
ind = [-10:10]; 
xval = xk(ind,h)';
mat1 =  skh_pp(-10,h,xval);
for i=-9:10,            % k ranges from -10 to 10
  mat1 = [mat1 skh_pp(i,h,xval)];
endfor
%----------- interior points, spline:
mat1 = [mat1 rig_val_pp(xval)];

%------------ right boundary, sincs:
mat2 = zeros(1,21);
%------------ right boundary, spline:
mat2 = [mat2 rig_val(1.0)];
%------------ combine:
mat = [mat1; mat2];

sv1 = svd(mat);          %% nasty tendency, poor conditioning.

col = 1./max(abs(mat));
smat = mat*diag(col);
row = 1./max(abs(smat'));
smat = diag(row)*smat;
 
sv2 = svd(smat);         %% same creeping sigmas, and conditioning is
                         %% one order worse than the "pure" u'' above. (90177.6)


                        
                        
%%============================================================================= 
%%       Form collocation matrix for u'' on the interior, u on the right
%%       boundary, u' on the left boundary, all using sinc basis/
%%       right value/ left derivative splines
%%============================================================================= 
% 
%       use 21 sinc terms, and 2 spline ==> need 23 points total, 21 interior
%----------- interior points, sincs:
ind = [-10:10]; 
xval = xk(ind,h)';
mat1 =  skh_pp(-10,h,xval);
for i=-9:10,            % k ranges from -10 to 10
  mat1 = [mat1 skh_pp(i,h,xval)];
endfor
%----------- interior points, splines:
mat1 = [mat1 rig_val_pp(xval)];
mat1 = [mat1 lef_der_pp(xval)];

%------------ right boundary, sincs:
mat2 = zeros(1,21);
%------------ right boundary, right spline:
mat2 = [mat2 rig_val(1.0)];
%------------ right boundary, left spline:
mat2 = [mat2 lef_der(1.0)];

%------------ left boundary, sincs:
mat3 = zeros(1,21);
%------------ left boundary, right spline:
mat3 = [mat3 rig_val_p(0.0)];
%------------ left boundary, left spline:
mat3 = [mat3 lef_der_p(0.0)];


%------------ combine:
mat = [mat1; mat2; mat3];

sv1 = svd(mat);          %% nasty tendency, poor conditioning.

col = 1./max(abs(mat));
smat = mat*diag(col);
row = 1./max(abs(smat'));
smat = diag(row)*smat;
 
sv2 = svd(smat);         %% same creeping sigmas, and conditioning is
                         %% two orders worse than the "pure" u''
                         %% above.(136709.1)


% 
%       The row scaling may be affected by the presence of the spline terms.
%       TESTED THIS: the splines ARE the row scales...
%       Thus, try a "local" scaling, for only the sinc series terms.
%       (the columns are independent):
col = 1./max(abs(mat));
smat = mat*diag(col);
row = 1./max(abs(smat(1:21,1:21)'));       % assuming above system sizes/ordering
smat = diag([row 1 1])*smat;
svtest = svd(smat);         %% same creeping sigmas, and conditioning is
%
%	RESULTS: worse than direct scaling.  Considering that the sinc
%	rows for the endpoints are zero, row-column equilibration is
%	the most general scaling anyway...



%                        
%%       If you don't need a spline, don't provide it !!
%                        
