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