function y = u_solve(U,y)
% y=u_solve(U,y)
% solve the matrix equation U*x=y
% U is an upper-triangular matrix
% y may have more than one column
% y is also the solution

% M. M. Sussman
% $Date: 2011/02/18 15:21:16 $

n=size(y,1);

if n~=size(U,1) | n~=size(U,2)
  error('u_solve: U and y do not have consistent dimensions');
end

for row=n:-1:1
  y(row,:) = (y(row,:) - U(row,row+1:n)*y(row+1:n,:)) / U(row,row);
end
