function [ y ] = full_pivot( A,b )
%Given an nxn matrix A and a length n vector b use full pivoting to solve
%the equation Ax=b.

%   A is the input matrix
%   b is the RHS vector, either as a row vector or as a column vector
%   y is the output vector, as the same type of vector as b

if det(A)==0
    error('The matrix A is singular, please enter a non-singular matrix')
end
n=size(A,1); % find the dimensions of A
m=n+1; %record the size of the soon to be augmented matrx A
A(:,m)=b(1:n); % this syntax allows a vector to be input as either a 
% row vector or a colum vector
A(m,:)=1:m; % number the columns of A for future referenc
temp_col=zeros(m,1);
temp_row=zeros(1,m);



for k=1:n
    % find the maximum element in the n-k+1,m-k+1 submatrix, in terms of
    % absolute value
    max_row_loc=0;
    max_col_loc=0;
    max_val=0;
    
    for j=k:n
        for l=k:n
           if abs(A(l,j))>max_val
               
               max_row_loc=l;
               max_col_loc=j;
               max_val=abs(A(l,j));
           end
        end
    end
    
    %swap rows and columns so the highest element in the submatrix is in
    %the k,k position of A
    temp_col=A(:,max_col_loc);
    A(:,max_col_loc)=A(:,k);
    A(:,k)=temp_col;
    temp_row=A(max_row_loc,:);
    A(max_row_loc,:)=A(k,:);
    A(k,:)=temp_row;
   
    
    % eleminate the elements above A(k,k)
    for j=1:k-1
       A(j,k+1:m)=A(j,k+1:m)-(A(j,k)/A(k,k))*A(k,k+1:m);
       A(j,k)=0;
    end
    
    % eleminate the elements below A(k,k)
    for j=k+1:n
       A(j,k+1:m)=A(j,k+1:m)-(A(j,k)/A(k,k))*A(k,k+1:m);
       A(j,k)=0;
    end
    
    % normalize the kth row to make solving for x easier.
    A(k,:)=A(k,:)./(A(k,k));
     
end

% return x to its original order and record its values. 
for k=1:n
    b(A(m,k))=A(k,m); % use b so that the vector returned is the same
    % type as the input vector
end

 y=b;

end
