function x  = samplegauss(a,b)
%The function samplegauss accepts a square matrix a and a column vector b
%and returns a vector of zeros. 

%This is an example to help us get started writing an m-file to
%carry out Gaussian elimination return a solution of ax = b.

%Russell Brown
%7 November 2004

[rowa, cola] = size(a);
[rowb, colb] = size(b);

%Check that sizes of the arguments are compatible. 
if (rowa ~= cola) 
	error('First argument should be a square matrix.')
end


if (colb ~= 1)
	error('Second argument should be a column vector.')
end

if (rowb ~= rowa)
	error('Provide a helpful error message');
end
%Augment a with b.
u = [a b];

%Check for divide by zero.  

    if (u(1,1) == 0 ) 
        error('Danger, will robinson')
    end

%In the code below, the expression u(k,[j:m]) stands for entries 
%j through m in the kth row of u.  
% 
%As noted in the text, there is no need to compute the entries below the
%pivot element, since they are supposed to be zero. However, it is
%reassuring to do the computation to make sure that we are on the right
%track.

%The next few statements eliminate the entries below the pivot element in
%the first column. Add a for loop to do this in the remaining columns. 

v = u(1,[1:rowa+1])/u(1,1);

for k = 2:rowa
        u(k,[1:rowa+1]) = u(k,[1:rowa+1]) - v*u(k,1); 
end
    
u

x= zeros(rowa,1);

%Add code for backsubstitution phase here. 