Trying to code the laplace expansion as i’m learning it in college and i’m stuck when it comes to getting the minor matrix of a big matrix. This are always square matrices and the minor matrix is always 1 size less than the big matrix, such that: matrix = nxn => minor = (n-1)x(n-1).
In this part of the code I get the minor such that for an element ‘a’ of the first row of the matrix the minor consist of all the values that are NOT in the same row or column as element ‘a’:
float minor[matrixDimension-1][matrixDimension-1];
for (i = 0; i < matrixDimension; i++) {
for (j = 1; j < matrixDimension; j++) {
for (k = 0; k < matrixDimension; k++) {
if(k != i) {
minor[j-1][k-1] = matrix[j][k];
}
}
}
printf("minor: n");
printf("%f, ", minor[0][0]);
printf("%f, n", minor[0][1]);
printf("%f, ", minor[1][0]);
printf("%f, n", minor[1][1]);
}
I want the matrix “minor” to always be filled with the correct matrix[j][k]
values but in the left to right, top to bottom order.
When testing with a 3×3 matrix and a 2×2 minor, the minor is only correct in the first iteration of the first for loop, since this line is the best i could come up for filling minor minor[j-1][k-1] = matrix[j][k];
.
Felipe Miklikowski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.