问题描述
我计算的产品,和,转(的产品),但我不知道从哪里开始在产品矩阵的辅助因子和行列式。
我见过一对夫妇的例子,但没有一个类似于我特别code,如果任何人能告诉我,我如何将这两种方法纳入我的程序我倒是高AP preciate它。
请不要问我什么,我已经试过,因为正如我所说,我无言以对的时刻
//这里是code我写的产品:包programEx;
进口java.io. *;
进口的java.util。*;
进口的java.io.File *。
进口java.util.Scanner中;公共类progEx { 公共静态无效的主要(字串[] args){
//建立输入流
扫描器S =新的扫描仪(System.in);
System.out.print(在一个输入行数:);
INT rowsInA = s.nextInt();
System.out.print(在A /排在b输入列数:);
INT columnsInA = s.nextInt();
System.out.print(输入B中的列数:);
INT columnsInB = s.nextInt(); INT [] []一个=新INT [rowsInA] [columnsInA];
INT [] [] B =新INT [columnsInA] [columnsInB]; //以用户输入1矩阵
的System.out.println(输入矩阵A);
的for(int i = 0; I<则为a.length;我++){
为(中间体J = 0; J&下;一个[0]。长度; J ++){
一个[I] [J] = s.nextInt();
}
}
//以用户输入第二矩阵
的System.out.println(输入矩阵B);
的for(int i = 0; I< b.length个;我++){
为(中间体J = 0; J&下; B [0]。长度; J ++){
B〔I] [J] = s.nextInt();
}
} //调用倍增法并将它传递给两个矩阵
INT [] [] C =乘(A,B);
的System.out.println(A的产品,B是);
的for(int i = 0; I< c.length;我++){
为(中间体J = 0; J&c为C [0]。长度; J ++){
System.out.print(C [I] [J] +); }
的System.out.println();
} }//为第一和第二矩阵乘法单独的方法
公共静态INT [] []乘(INT [] []一,INT [] [] B){
INT rowsInA =则为a.length;
INT columnsInA =一个[0]。长度;
INT columnsInB = B [0]。长度;
INT [] [] C =新INT [rowsInA] [columnsInB];
的for(int i = 0; I< rowsInA;我++){
对于(INT J = 0; J< columnsInB; J ++){
对于(INT K = 0; K< columnsInA; k ++){
C [I] [J] = C [I] [J] + A [I] [K] * B [k]的[J]。
}
}
}
返回℃;
}
}
好了,一个3 * 3的矩阵有3列和3行的开始。
每始于指数0。
行列式可以计算为:
INT D =行列式();
INT决定()
{
INT X = A [0] [0] *((一[1] [1] *一个[2] [2]) - (一[2] [1] *一个[1] [2]));
INT Y = -a [0] [1] *((一个[0] [1] *一个[2] [2]) - (一[2] [0] *一[1] [2]));
INT Z = A [0] [2] *((一[1] [0] *一个[2] [1]) - (一[1] [1] *一个[2] [0])); INT R = X + Y + Z;
返回ř;
}
这是只为寻找一个3×3矩阵的行列式。
I computed the product, sum, and transpose(of product), but I have no clue where to start on the cofactor and determinent of the product matrix.
Ive seen a couple examples but none that resemble my particular code so if anyone could show me how i could incorporate these two methods into my program I'd high appreciate it.
please dont ask me what i've tried because as I stated I am clueless at the moment
//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;
}
}
Well,a 3*3 matrix has 3 columns and 3 rows to begin with.Each starts with an index 0.
Determinant can be calculated as:
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;
}
This is only for finding the determinant of a 3*3 matrix.
这篇关于找到一个3x3矩阵的辅助因子和决定因素(JAVA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!