% Test forwardSubstitutionR.m & forwardSubstitutionC.m
% for solving a lower triangular system by forward-substitution.
% forwardSubstitutionR.m uses row access of the matrix while
% forwardSubstitutionC.m uses column access.
% Input matrix LOWER is an n by n lower triangular matrix
% Input vector Bvec is n by 1
% Input scalar n specifies the dimensions of the arrays
% Output vector x is the solution to the linear system
% LOWER x = Bvec
% K. Ming Leung, 01/25/03, 02/16/05 (using better variable names)

clear all;
LOWER = [ 1  0  0
          2 -4  0
          2 -6 -1];
Bvec = [3; -6; 1];

n = 3000; LOWER = rand(n,n); Bvec = rand(n,1); n = length(Bvec); 
%
loopMax = 13;
% Row processing takes a little longer in MATLAB
tic;
for loop = 1:loopMax
XvecR = forwardSubstitutionR(LOWER,Bvec,n); end; toc;  

tic;
for loop = 1:loopMax
XvecC = forwardSubstitutionC(LOWER,Bvec,n); end; toc; 

error = max(abs(XvecR-XvecC)),