function C=cofactorMatrix(A)
%%COFACTORMATRIX Compute the cofactor matrix of a square matrix A. The cofactor
%     matrix of a matrix A is one such that C(i,j)=(-1)^(i+j)det(A_{i,j}), where
%     A_{i,j} is the matrix A with row i and column j removed.
%
%INPUTS: A An nXn square matrix. The elements can be real or complex. The
%          matrix can be singular.
%
%OUTPUTS: C The nXn cofactor matrix of the matrix A.
%
%The adjugate of a matrix is defined in Ch. 4 of [1] as the transpose of the
%cofactor matrix C. This function just calls adj(A) to get the adjugate and then
%takes the transpose of the result.
%
%REFERENCES:
%[1] K. M. Abadir and J. R. Magnus, "Matrix algebra," New York, 2005.
%
%August 2020 David F. Crouse, Naval Research Laboratory, Washington D.C.
%(UNCLASSIFIED) DISTRIBUTION STATEMENT A. Approved for public release.

C=adj(A)';

end
