%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   my scripts for bits and pieces of the Tridiagonal demonstration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function A = setA(N)
% SETA - setup a tridiagonal 1-D laplacian matrix with dirichlet BC's
%   
  
%
%  set up sparse tridiagonal matrix A (which is mostly 2's on the diagonal and -1 
%  on the first super and subdiagonal
%
  A=spalloc(N,N,3*N);  % allocate room for a NxN sparse matrix with max 3N entries
% 
% set the matrix for the Boundary tanks 1 and N
% 
  
  A(1,1)=1;
  A(N,N)=1;

%
% set the interior rows of the matrix (p.s. this isn't the fastest way
% to do this but it might be the clearest
%

  for k=2:N-1
    A(k,k-1:k+1)=[ -1 2 -1 ];  % just sets the 3 non-zero elements of row k
  end
  
  verbose=false;
  if (verbose)
    disp(sprintf('\n Here are the first 5 rows of A\n'));
    disp(full(A(1:5,1:5)))
  end   
  
  return
 