function [D] =compute_determinant (A )
% This function computes the determinant of a matrix
% by using Gauss elimination with pivoting by 
% row (partial pivoting)
% 
% Input: A -> matrix m x n with real coefficients
%
% Output D -> determinant of A

[m,n]=size(A);

IDX=1;
for kk=1:m-1

    [a,idx]=max(abs(A(kk:end,kk)));
    
    if idx~=kk   % PIVOTING STEP
        q = A(kk, kk:end);
        A(kk,kk:end)=A(idx+kk-1,kk:end);
        A(idx+kk-1,kk:end)=q;
        IDX=IDX+1;
    end
    
     for jj=kk+1:m % ELIMINATION STEP
         A(jj,kk:end)=A(jj,kk:end)-A(kk,kk:end)*A(jj,kk)/A(kk,kk);
     end
end
    
D=(-1)^IDX*prod(diag(A));
    
    

end

