%
% To solve an upper triangular system Ax = b by back-substitution
%

function x = backsubst(A,b)
n = size(A, 1);
x = zeros(n,1);
x(n) = b(n)/A(n,n);
  for i = 1: n-1
     rhs = A(n - i,(n - i + 1):n)*x((n - i + 1):n);
     x(n - i) = (b(n - i) - rhs)/A(n - i,n - i);
  end
end



