%-------------------------------------------------------------------------------
%-------------------------------------------------------------------------------
%
%  This function solves the problem Ax=b where A must be an 
%  upper triangular matrix
%
%-------------------------------------------------------------------------------
%-------------------------------------------------------------------------------

function x  =  MyUpperSubstitution(A,b)
%--------------------------------  
% Check dimensions of A
%--------------------------------  
n  =  size(A,1);
m  =  size(A,2);
if abs(n-m)>0
  error('The matrix A must be squared')  
end

x    =  zeros(n,1);
for i=1:n
    alpha  =  n-(i-1);
    x(alpha)  =  b(alpha);
    for j=1:i-1
        beta      =  n - (j-1);
        x(alpha)  =  x(alpha) - A(alpha,beta)*x(beta);
    end
    x(alpha)    =  x(alpha)/A(alpha,alpha);
end
