%------------------------------------------------------------------------------
% ------< 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 nX1, and x is nX1
%------------------------------------------------------------------------------
n = length(b);
x = zeros(n,1);
for j = n:-1:2
x(j) = b(j)/U(j,j);
b(1:j-1) = b(1:j-1) - x(j)*U(1:j-1,j);
end
x(1) = b(1)/U(1,1);
%------------------------------------------------------------------------------