这篇文章主要介绍了java实现任意矩阵Strassen算法的相关资料,需要的朋友可以参考下
本例输入为两个任意尺寸的矩阵m * n, n * m,输出为两个矩阵的乘积。计算任意尺寸矩阵相乘时,使用了Strassen算法。程序为自编,经过测试,请放心使用。基本算法是:
1.对于方阵(正方形矩阵),找到最大的l, 使得l = 2 ^ k, k为整数并且l
StrassenMethodTest.java
package matrixalgorithm; import java.util.Scanner; public class StrassenMethodTest { private StrassenMethod strassenMultiply; StrassenMethodTest(){ strassenMultiply = new StrassenMethod(); }//end cons public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Input row size of the first matrix: "); int arow = input.nextInt(); System.out.println("Input column size of the first matrix: "); int acol = input.nextInt(); System.out.println("Input row size of the second matrix: "); int brow = input.nextInt(); System.out.println("Input column size of the second matrix: "); int bcol = input.nextInt(); double[][] A = new double[arow][acol]; double[][] B = new double[brow][bcol]; double[][] C = new double[arow][bcol]; System.out.println("Input data for matrix A: "); /*In all of the codes later in this project, r means row while c means column. */ for (int r = 0; r
StrassenMethod.java
package matrixalgorithm; import java.util.Scanner; public class StrassenMethod { private double[][][][] A = new double[2][2][][]; private double[][][][] B = new double[2][2][][]; private double[][][][] C = new double[2][2][][]; /*//Codes for testing this class: public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Input size of the matrix: "); int n = input.nextInt(); double[][] A = new double[n][n]; double[][] B = new double[n][n]; double[][] C = new double[n][n]; System.out.println("Input data for matrix A: "); for (int r = 0; r
希望本文所述对大家学习java程序设计有所帮助。
以上就是java实现任意矩阵Strassen算法的详细内容,更多请关注0133技术站其它相关文章!