function x=ForwSub(L,b)
% This function computes the vector x, of length n, 
% given Lx=b where L is an nxn, non-singular lower triangular matrix 
% and b is an known vector of length n, 
% by using forward substitution. 

%% Compute x by forward substitution.
s=size(L);
n=s(1);
x=zeros(n,1);
% L(i,i)*x(i)=b(i)-sum_{j=1}^{i-1}
for i=1:n
    x(i)=b(i); % first set x(i)=b(i)
    for j=1:(i-1)
        x(i)=x(i)-L(i,j)*x(j); % then subtract known values. 
    end
    x(i)=x(i)/L(i,i); % Lastly divide by diagonal entry L(i,i)
end
end