# Laplace Expansion

The determinant of any square matrix can be found trough Laplace Expansion. The formula presented in section 7a: 2x2 determinant to find the determinant of a 2x2 matrix is the result of Laplace Expansion.

To find the determinant of a matrix trough Laplace Epxansion, multiply every element in the top row by it's cofactor and sum the result. The formula looks like this:

$$| M | = \sum_{i=1}^{n} M_{1i}cofactor(M_{1i})$$

It doesn'thave to be the first row, any row will do. The choice to use the first row is arbitrary.

The implementation provided here is naive. Calling Cofactor will calculate the entire cofactor matrix, which is not desired. Instead of doing exactly this, try to manually inline the work so the Determinant function does not call any other functions.

float Determinant(mat3 m) {
mat3 c = Cofactor(m);

float _11 = m.v * c.v;
float _12 = m.v * c.v;
float _13 = m.v * c.v;

return _11 + _12 + _13;
}

float Determinant(mat4 m) {
mat4 c = Cofactor(m);

float _11 = m.v * c.v;
float _12 = m.v * c.v;
float _13 = m.v * c.v;
float _14 = m.v * c.v;

return _11 + _12 + _13 + _14;
}