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