function x = ubi_sol ( uvec, sup, b )

%  UBI_SOL solves an upper bidiagonal linear system.
%
%  function x = ubi_sol ( uvec, sup, b )
%
%  real UVEC(N) is the diagonal values.
%  real SUP(1:N-1) is the superdiagonal values.
%  real B(N) is the right hand side.
%
%  real X(N) is the solution.
%
%  Reference:
%
%    Charles Van Loan,
%    Introduction to Scientific Computing,
%    Prentice Hall, 1997.
%
  n = length ( b ); 
  x = zeros ( n, 1 );

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