function T = symtridiag(d,e,initialization)
%
% return the tridiagonal matrix with diagonal d and subdiagonal and superdiagonal e
%
% initialization == 0: no initialization: very slow
% initialization == 1: initialize T to be a "full" matrix: much faster
% initialization == 2: initialize T to be a "sparse" matrix: no faster for the
%  initialization, but much faster if follow this with computing the LU
%  factorization
%  
%  can use this function to compare timings for these using "tic...toc" 
%   (or "timeit", but then need to write a wrapper if want to time LU, inv, etc)
initialization
n = length(d);
if length(e) ~= n-1
    error('lengths of d,e not compatible')
end
if initialization == 0
    % do no pre-allocation
    % the program will still run correctly, but it will
    % take MUCH longer to run than version == 1 since it 
    % reallocates space for T every time  through the loop
elseif initialization == 1
    T=zeros(n,n); % set T to be an n by n full zero matrix
elseif initialization == 2
    T=sparse(n,n); % set To be an n by n sparse zero matrix
else
    error('illegal version')
end
% set T to a tridiagonal matrix  
for i=1:n-1 
    T(i,i) = d(i);
    T(i,i+1) = e(i);
    T(i+1,i) = e(i);
end
T(n,n) = d(n);