Calculation of the Cofactor matriz of a Matrix A of size nxn

Hi everyone,

Has anyone ever come across the calculation of the cofactor matrix of a square matrix. Any idea how that can be done?
Here is an example of a 3x3 matrix (I need to do the same for a nxn).


As you can see the element i,j of the cofactor matrix C, is the determinant of a submatrix of A, that does not contain the row i and column j.

I did look in the library and there is not a method to do this directly.

Mi idea is to do my own method that does the following:

For every i,j

  1. Copy the matrix A into a another matrix lets say M
  2. Remove row i from matrix M with the method using a new matrix R= M.RemoveRow(i)
  3. Remove column j from matrix M with the method using a new matrix Q= M.RemoveColumn(j)
  4. Calculate the determinant of Q Q.determinat()
  5. Store the determinant of Q in C[i,j] with the proper sign

Any other idea that maybe faster??

Any help will be greatly appreciated.