function x = tridiagonalSolver( a, d, c, b )
  %--------------------------------------------------------------------------
  % Jonathan R. Senning <jonathan.senning@gordon.edu>
  % Gordon College
  % March 1, 1999
  %
  % Usage: x = tridiagonalSolver( a, d, c, b )
  %
  % Returns:
  %	x:	solution vector
  %
  % Parameters:
  %	a,d,c:	diagonals of the tridiagonal matrix A.  a is the subdiagonal
  %			with a(1) being the A(2,1) value, d is the main
  %			diagonal with d(1) being the A(1,1) value and c is
  %			the superdiagonal with c(1) being the A(1,2) value.
  %	b:	right-hand-side vector.
  %
  % This function solves the linear system Ax = b when A is a tridiagonal
  % matrix.  For this to be sure to work A should be strictly diagonally
  % dominant, meaning that |d(i)| > |a(i-1)| + |c(i)|.
  %
  % NOTE: No error checking is performed on the bounds of any of the input.
  % It is assumed that both b and d are nx1 and both a and c are at least
  % (n-1)x1.
  %
  %--------------------------------------------------------------------------

  [n, m] = max( size( d ) );

  for i = 2 : n
    xmult = a(i-1) / d(i-1);
    d(i) = d(i) - xmult * c(i-1);
    b(i) = b(i) - xmult * b(i-1);
  end

  x = zeros( n, 1 );
  x(n) = b(n) / d(n);

  for i = n - 1 : -1 : 1
    x(i) = ( b(i) - c(i) * x(i+1) ) / d(i);
  end

end
