function x = i4mat_u_solve ( n, a, b )

%*****************************************************************************80
%
%% i4mat_u_solve() solves an upper triangular linear system.
%
%  Discussion:
%
%    An I4MAT is an MxN array of I4's, stored by (I,J) -> [I+J*M].
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    28 July 2015
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of rows and columns of
%    the matrix A.
%
%    integer A(N,N), the N by N upper triangular matrix.
%
%    integer B(N,1), the right hand side of the linear system.
%
%  Output:
%
%    real X(N,1), the solution of the linear system.
%
  b = b(:);
%
%  Solve U * x = b.
%
  x = zeros ( n, 1 );

  for i = n : -1 : 1
    x(i,1) = b(i,1);
    for j = i + 1 : n
      x(i,1) = x(i,1) - a(i,j) * x(j,1);
    end
    x(i,1) = x(i,1) / a(i,i);
  end

  return
end
