Wednesday, 15 April 2015

Co Factor of a Matrix in Java (used to determine the inverse of a matrix) -



Co Factor of a Matrix in Java (used to determine the inverse of a matrix) -

i trying determine inverse of matrix using adjoint method i.e. (first calculate cofactor of matrix, transpose matrix , finally, multiply (1/determinant) inverse of value of determinant) have methods determine transpose , determinant, struggling cofactor matrix -

link showing how inverse determined using adjoint method hand http://www.mathwords.com/i/inverse_of_a_matrix.htm link showing how cofactor calculated hand http://www.mathwords.com/c/cofactor_matrix.htm>

i have method calculates determinant , transpose fine, cant cofactor method give me output require

a sample output => 24 5 -4 24 5 -4 24 5 -4 sec & 3rd row should different, suggestions? thanks! here method using => checkifsquare , assigningsign methods working fine

public static int[][] cofactor(int[][] matrix) { int[][] cofactormatrix = new int[matrix.length][matrix.length]; (int j = 0; j < matrix.length; j++) { if (checkifsquare(matrix)) { (int location = 0; location < matrix.length; location++) { int reducedmatrix[][] = new int[matrix.length - 1][matrix.length - 1]; (int rows = 1; rows < matrix.length; rows++) { (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; } } } homecoming cofactormatrix; }

when calculate reducedmatrix skip on first row. works first row of cofactor matrix, rows below need skip on row j. why output consists of first row repeated.

by way, horrible way calculate inverse of matrix. assume academic exercise, not meant used in serious programs.

java matrix matrix-inverse

No comments:

Post a Comment