function T = inittridiag(diagonal,superd,subd)
% MATLAB function for the initialization of a sparse tridiagonal matrix. The
% argument \texttt{diagonal} has to pass a vector of lenth $N$, which is used to
% initialize the diagonal of the matrix, whereas the $N-1$-vectors
% \texttt{superd} and \texttt{subd} contain the entries for super- and
% sub-diagonal of the matrix. 
N = length(diagonal); % we aim for an $N\times N$ tridiagonal matrix
if ((length(superd) ~= N-1) || (length(subd) ~= N-1))
  error('length mismatch for offdiagonals');
end
I = [1:N,1:N-1,2:N]; % row indices for non-zero matrix entries
J = [1:N,2:N,1:N-1]; % column indices for non-zero matrix entries
a = [diagonal;superd;subd]; % Value vector for matrix entries
% Initialization of sparse $N\times N$-matrix from tupels $(i,j,a_{i,j})$.
T = sparse(I,J,a,N,N);

