function x=forwardSubstitutionC(L,b,n)
% Solving a lower triangular system L x = b by forward-substitution.
% Input matrix L is an n by n lower triangular matrix
% Input vector b is n by 1
% Input scalar n specifies the dimensions of the arrays
% Output vector x is the solution to the linear system
% This version uses column processing (good for Fortran).
% K. Ming Leung, 01/25/03

x = zeros(n,1);  % initialization for efficiency purpose only
for j = 1:n
    if (L(j,j)==0) error('Matrix is singular!'); end;
    x(j) = b(j)/L(j,j);
    % Column processing: involves the jth column of L 
    % below the main diagonal
    b(j+1:n) = b(j+1:n)-L(j+1:n,j)*x(j); % involves a scalar multiplying a vector
end       
