## Cofactor

To get a **cofactor of matrix**, you first need to find the matrix of minor for that matrix. Given matrix *M*, find the cofactor of element and multiply the minor of that element by -1 raised to the power:

### Getting ready

We're going to create a generic function that will find the matrix of cofactors for any sized matrix, given the matrix of minors. We're going to call this generic `Cofactor`

function from more specific `Cofactor`

functions for 2 X 2 and 3 X 3 matrices.

### How to do it…

Follow these steps to implement a generic cofactor function which will work on matrices of any size. We will use this generic function to implement the specific two and three dimensional square matrix cofactor functions:

Declare all versions of the

`Cofactor`

function in`matrices.h`

:void Cofactor(float* out, const float* minor, int rows, int cols); mat3 Cofactor(const mat3& mat); mat2 Cofactor(const mat2& mat);

Implement the generic

`Cofactor`

function in`matrices.cpp`

:void Cofactor(float* out, const float* minor...