function [ lvec, uvec ] = tri_fac ( sub, diag, sup )
%
%  TRI_FAC computes the LU factors of a tridiagonal matrix.
%
%  function [ lvec, uvec ] = tri_fac ( sub, diag, sup )
%
%  real SUB(1:N-1), the subdiagonal elements of the matrix.
%  real DIAG(N), the diagonal elements of the matrix.
%  real SUP(1:N-1), the superdiagonal elements of the matrix.
%
%  real LVEC(N), the lower diagonal of the unit L factor.
%  real UVEC(N), the diagonal of the U factor.  SUP is the superdiagonal.
%
%  Warning:
%
%    The factorization is done without pivoting.  This procedure
%    can give poor results, or break down entirely.  It is
%    guaranteed to work well when the matrix is positive definite.
%
%  Reference:
%
%    Charles Van Loan,
%    Introduction to Scientific Computing,
%    Prentice Hall, 1997.
%
  n = length ( diag ); 
  lvec = zeros ( n, 1 ); 
  uvec = zeros ( n, 1 );

  uvec(1) = diag(1);
  for i = 2: n
    lvec(i) = sub(i-1) / uvec(i-1);
    uvec(i) = diag(i) - lvec(i) * sup(i-1);
  end
