function y = ForwardSub(A,b) % The function solves a system of linear equations ax = b %Step 4 (page 122). % where a is lower triangular matrix by using forward substitution. % Input variables: % a The matrix of coefficients. % b A column vector of constants. % Output variable: % y A column vector with the solution. n=length(b); y(1,1)=b(1)/A(1,1); for i=2:n y(i,1)=(b(i)-A(i,1:i-1)*y(1:i-1,1)) ./A(i,i); end