function x=backsub2(R,temp)
%solves of Rx=temp by back substitution
%R is upper triangular with no zeros on the diagonal
%R is n x n and temp is an n-vector
n=size(R,1);
x(n)=temp(n)/R(n,n);
for i=n-1:-1:1;
    sum=temp(i);
    for j=i+1:n;
        sum=sum-R(i,j)*x(j);
    end;
    x(i)=sum/R(i,i);
end;