Note that there are some explanatory texts on larger screens.

plurals
  1. POCo Factor of a Matrix in Java (used to determine the inverse of a matrix)
    primarykey
    data
    text
    <p>I am trying to determine the inverse of a matrix using the adjoint method i.e. (First calculate the cofactor of the matrix, then transpose this matrix and finally, multiply it by (1/determinant) for the inverse of the value of the determinant) I have methods that determine the transpose and determinant, however i am struggling with the cofactor matrix -</p> <p>Link showing how the inverse is determined using the adjoint method by hand <a href="http://www.mathwords.com/i/inverse_of_a_matrix.htm" rel="nofollow">http://www.mathwords.com/i/inverse_of_a_matrix.htm</a> Link showing how the cofactor is calculated by hand <a href="http://www.mathwords.com/c/cofactor_matrix.htm" rel="nofollow">http://www.mathwords.com/c/cofactor_matrix.htm</a>></p> <p>I have a method that calculates the determinant and the transpose fine, but I cant get the cofactor method to give me the output I require</p> <p>A sample output is => 24 5 -4<br> 24 5 -4<br> 24 5 -4 but the second &amp; third row should be different, any suggestions? Thanks! Here is the method that I am using => The checkIfSquare and assigningSign methods are working fine also </p> <pre><code> public static int[][] cofactor(int[][] matrix) { int[][] cofactorMatrix = new int[matrix.length][matrix.length]; for (int j = 0; j &lt; matrix.length; j++) { if (checkIfSquare(matrix)) { for (int location = 0; location &lt; matrix.length; location++) { int reducedMatrix[][] = new int[matrix.length - 1][matrix.length - 1]; for (int rows = 1; rows &lt; matrix.length; rows++) { for (int cols = 0; cols &lt; matrix.length; cols++) { if (cols &gt; location) { reducedMatrix[rows - 1][cols - 1] = matrix[rows][cols]; } else if (cols &lt; location) { reducedMatrix[rows - 1][cols] = matrix[rows][cols]; } } } int sign = assigningSign(location); cofactorMatrix[j][location] = determinantCalc(reducedMatrix) * sign; } } } return cofactorMatrix; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload