I don't know If I should post here, but I'm having trouble with the algorithm, so maybe I can then translate it into code.
I'm having trouble figuring out a way to make this algorithm work, as I can't figure out how to do the middle part of the problem. Just for reference, here's my code so far:
int det(int matrixSize, int matrix[][matrixSize]){
int determinant=0, matrixValues[matrixSize*matrixSize], matrixFirstRowValues[matrixSize*matrixSize];
for(int i=matrixSize;i>2;i--){
for(int row=0;row<matrixSize;row++){
for(int col=0;col<matrixSize;col++){
matrixFirstRowValues[row+(matrixSize-i)]=matrix[1][col+(matrixSize-i)];
//copies the first row values for an array until we have a 2x2 matrix
}
}
}
//multiply the values in matrix Values by their respective matrix without
//the row and column of these values times -1^row+col
determinant+=(matrix[matrixSize-1][matrixSize-1]*matrix[matrixSize-2][matrixSize-2])-(matrix[matrixSize-1][matrixSize-2]*matrix[matrixSize-2][matrixSize-1]);
return determinant;
}
Being the matrix, a 2-dimensional array with the size of matrixSize, I iterate through it until I'm left with a 2x2 matrix, copying each value of the first row to a new array.
Those values have to be multiplied by the matrix that it's left when I remove the row and column where that value is.
This is the principle of the laplace expansion. The part that's giving me trouble is getting those matrices that are left by removing rows and columns, as I want this to work for a nxn matrix.
Then, in the end the sum that to the det of a 2x2 matrix.
How can I do the middle part (where the comments are) with my current setup?