2015-11-29 22 views
0

我計算了產品,總和和轉置(產品),但我不知道從哪裏開始輔助因子和產品矩陣的確定。找到3×3矩陣的輔助因子和決定因素(java)

我見過幾個例子,但沒有一個類似於我的特定代碼,所以如果有人能告訴我如何將這兩種方法合併到我的程序中,我會非常感激。

請不要問我什麼,我已經試過,因爲我說我無能,此刻

//here is the code I wrote for the product: 

package programEx; 
import java.io.*; 
import java.util.*; 
import java.io.File.*; 
import java.util.Scanner; 

public class progEx { 

    public static void main(String[] args) { 
    //Establishing Input Stream 
     Scanner s = new Scanner(System.in); 
     System.out.print("Enter number of rows in A: "); 
     int rowsInA = s.nextInt(); 
     System.out.print("Enter number of columns in A/rows in B: "); 
     int columnsInA = s.nextInt(); 
     System.out.print("Enter number of columns in B: "); 
     int columnsInB = s.nextInt(); 

     int[][] a = new int[rowsInA][columnsInA]; 
     int[][] b = new int[columnsInA][columnsInB]; 

//Taking user input for 1st matrix 
     System.out.println("Enter matrix A"); 
     for (int i = 0; i < a.length; i++) { 
      for (int j = 0; j < a[0].length; j++) { 
       a[i][j] = s.nextInt(); 
      } 
     } 
//Taking user input for 2nd matrix 
     System.out.println("Enter matrix B"); 
     for (int i = 0; i < b.length; i++) { 
      for (int j = 0; j < b[0].length; j++) { 
       b[i][j] = s.nextInt(); 
      } 
     } 

//calling the multiplication method and passing it to both matrices 
     int[][] c = multiply(a, b); 
     System.out.println("Product of A and B is"); 
     for (int i = 0; i < c.length; i++) { 
      for (int j = 0; j < c[0].length; j++) { 
       System.out.print(c[i][j] + " "); 

      } 
      System.out.println(); 
     } 

    } 

//Separate method for the multiplication of 1st and 2nd matrices 
    public static int[][] multiply(int[][] a, int[][] b) { 
     int rowsInA = a.length; 
     int columnsInA = a[0].length; 
     int columnsInB = b[0].length; 
     int[][] c = new int[rowsInA][columnsInB]; 
     for (int i = 0; i < rowsInA; i++) { 
      for (int j = 0; j < columnsInB; j++) { 
       for (int k = 0; k < columnsInA; k++) { 
        c[i][j] = c[i][j] + a[i][k] * b[k][j]; 
       } 
      } 
     } 
     return c; 
    } 
} 
+0

笨蛋不是一個好的開始。矩陣的行列式和輔因子應該是你所知道的。如果你可以計算矩陣的那些,那麼你可以做兩個矩陣的乘積。 – duffymo

回答

1

好了,一個3×3矩陣有3列3行開始。 每個具有索引0開始

行列式能夠計算爲:

int d=determinant(); 
int determinant() 
{ 
    int x=a[0][0]*((a[1][1]*a[2][2])-(a[2][1]*a[1][2])); 
    int y=-a[0][1]*((a[0][1]*a[2][2])-(a[2][0]*a[1][2])); 
int z=a[0][2]*((a[1][0]*a[2][1])-(a[1][1]*a[2][0])); 

    int r=x+y+z; 
    return r; 
    } 

這僅僅是用於查找3×3矩陣的行列式。

+0

謝謝兄弟,幫助 – aSad

+0

我很高興它的工作! 快樂學習! :) –