2013-02-13 1 views
1

나는 행렬의 역함수를 결정하려고합니다. 즉, 행렬의 보조 계수를 먼저 계산 한 다음이 행렬을 조인하고 마지막으로자바의 행렬 계수 (행렬의 역행렬을 계산할 때 사용)

링크 역이 결정되는 방법을 도시 - I하지만 난 보조인 행렬 고민하고, 트랜스 및 결정을 결정할 방법을 갖고) 행렬식의 값의 역수 (1/결정)에 의해 곱 adjoint 메서드를 사용하여 손으로 http://www.mathwords.com/i/inverse_of_a_matrix.htm 보조자가 손으로 계산하는 방법을 보여주는 링크

나는 결정과 트랜스의 벌금을 계산하는 방법을 가지고,하지만 난 나에게 내가

필요한 출력을 제공하기 위해 공동 인자 방법을 얻을 질수 출력 예제 => 24 (5) -4
24 (5) -4
입니다 24 5 -4하지만 두 번째 & 세 번째 행은 달라야합니다. 제안 사항은 무엇입니까? 감사! 는 여기가 checkIfSquare 및 assigningSign 방법도

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; 
} 

답변

1

에서 확인할 수있다. cofactor 행렬의 첫 번째 행에 대해서는 작동하지만 아래 행에 대해서는 행 j를 건너 뛸 필요가 있습니다. 이것이 첫 번째 행이 반복되는 결과입니다.

그건 그렇고, 이것은 행렬의 역함수를 계산하는 끔찍한 방법입니다. 나는 이것이 진지한 프로그램에 사용되기위한 것이 아니라 학문적 활동이라고 가정합니다.

0

잘 작동하는 바퀴를 다시 발명 할 필요가 없다 => 을 사용하고있는 방법이다. Jama는 잘 쓰여진 패키지입니다. 당신은 항상 첫 번째 행을 건너 reducedMatrix을 계산할 때 메이븐 저장소

<dependency> 
     <groupId>Jama</groupId> 
     <artifactId>Jama</artifactId> 
     <version>1.0.2</version> 
    </dependency> 

    <repository>  
     <id>ebi-repo</id>  
     <name>The EBI internal repository</name>  
     <url>http://www.ebi.ac.uk/~maven/m2repo</url>  
     <releases>  
      <enabled>true</enabled>  
     </releases>  
     <snapshots>  
      <enabled>false</enabled>  
     </snapshots> 
    </repository>   

또는 jar 파일은 http://math.nist.gov/javanumerics/jama/#Package