我正在尝试使用伴随方法确定矩阵的逆,即(首先计算矩阵的余因子,然后转置该矩阵,最后将其乘以(1/行列式)作为行列式值的倒数) 我有确定转置和行列式的方法,但是我正在努力处理辅因子矩阵 -
显示如何使用伴随方法手动确定逆数的链接 http://www.mathwords.com/i/inverse_of_a_matrix.htm 显示如何手动计算辅因子的链接 http://www.mathwords.com/c/cofactor_matrix.htm >
我有一个可以很好地计算行列式和转置的方法,但我无法使用辅因子方法来为我提供所需的输出
示例输出为 =>
24 5 -4
24 5 -4
24 5 -4 但第二行和第三行应该不同,有什么建议吗?谢谢!
这是我正在使用的方法=>
checkIfSquare 和 allocateSign 方法也工作正常
public static int[][] cofactor(int[][] matrix) {
int[][] cofactorMatrix = new int[matrix.length][matrix.length];
for (int j = 0; j < matrix.length; j++) {
if (checkIfSquare(matrix)) {
for (int location = 0; location < matrix.length; location++) {
int reducedMatrix[][] = new int[matrix.length - 1][matrix.length - 1];
for (int rows = 1; rows < matrix.length; rows++) {
for (int cols = 0; cols < matrix.length; cols++) {
if (cols > location) {
reducedMatrix[rows - 1][cols - 1] = matrix[rows][cols];
} else if (cols < location) {
reducedMatrix[rows - 1][cols] = matrix[rows][cols];
}
}
}
int sign = assigningSign(location);
cofactorMatrix[j][location] = determinantCalc(reducedMatrix) * sign;
}
}
}
return cofactorMatrix;
}
最佳答案
当你计算reducedMatrix
时,你总是跳过第一行。这适用于辅因子矩阵的第一行,但对于下面的行,您需要跳过第 j 行。这就是为什么您的输出包含重复的第一行。
顺便说一句,这是计算矩阵逆的一种可怕的方法。我认为这是一项学术练习,不适合在严肃的程序中使用。
关于java - Java 中矩阵的余因子(用于确定矩阵的逆),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14850173/