%------------------------------------------------------------------------------
%                 ------< X = UTriInv(U) >------
%------------------------------------------------------------------------------
 function X = UTriInv(U)
%         X = UTriInv(U)
% Solves the nonsingular upper triangular system Ux = b.
% where U is nXn, B is nXr, and X is nXr
%------------------------------------------------------------------------------
[n,n] = size(U);
B = eye(n,n);
X = zeros(n,n);
for j = n:-1:2
   X(j,1:n) = B(j,1:n)/U(j,j);
   B(1:j-1,1:n) = B(1:j-1,1:n) - U(1:j-1,j)*X(j,1:n);
end
X(1,1:n) = B(1,1:n)/U(1,1);
%------------------------------------------------------------------------------
