function x=forwsub(L,b)
% solves L*x=b by forward substitution
% L is an n-by-n lower triangular matrix
% b is an n-vector

[n,m]=size(L);
x=zeros(n,1);
for i=1:n
    x(i)=(b(i)-L(i,1:i-1)*x(1:i-1))/L(i,i);
end
