public class MyMatrix { //double[][] A = { { 4.00, 3.00 }, { 2.00, 1.00 } }; //double[][] B = { { -0.500, 1.500 }, { 1.000, -2.0000 } }; public static double[][] multiplicar(double[][] A, double[][] B) { int aRows = A.length; int aColumns = A[0].length; int bRows = B.length; int bColumns = B[0].length; if (aColumns != bRows) { throw new IllegalArgumentException("A:Rows: " + aColumns + " did not match B:Columns " + bRows + "."); } double[][] C = new double[aRows][bColumns]; for (int i = 0; i < aRows; i++) { for (int j = 0; j < bColumns; j++) { C[i][j] = 0.00000; } } for (int i = 0; i < aRows; i++) { // aRow for (int j = 0; j < bColumns; j++) { // bColumn for (int k = 0; k < aColumns; k++) { // aColumn C[i][j] += A[i][k] * B[k][j]; } } } return C; } public static void main(String[] args) { final int size=1000; long t0, t1; double[][] A = new double[size][size]; double[][] B = new double[size][size]; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { // fill in some data A[i][j] = 0.5 + i+j; B[i][j] = 0.5 + j-i; } } for (int k = 0 ; k < 3 ; k++) { t0 = System.nanoTime(); double[][] result = multiplicar(A, B); t1 = System.nanoTime() - t0; System.out.println("Matrix multiply: no invert, size: " + size + " x " + size + " time: " + t1/1000000000.0 + " s, per element : " + 1.0*t1/size/size/size + " ns"); }; } }