Java Matrix matrix_x_matrix(double[][] A, double[][] B)

Here you can find the source of matrix_x_matrix(double[][] A, double[][] B)

Description

Multiplies two matrices.

License

Open Source License

Parameter

Parameter Description
A Matrix (m x n).
B Matrix (n x o).

Return

The resulting matrix of size m x o.

Declaration

public static double[][] matrix_x_matrix(double[][] A, double[][] B) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  w  w w  .  j  a  va 2s .  com
     * Multiplies two matrices.
     * @param A Matrix (m x n).
     * @param B Matrix (n x o).
     * @return The resulting matrix of size m x o.
     */
    public static double[][] matrix_x_matrix(double[][] A, double[][] B) {

        final int nA = A[0].length;
        final int mC = A.length;
        final int nC = B[0].length;

        final double[][] C = new double[mC][nC];

        for (int i = 0; i < mC; i++) {
            final double[] C_row = C[i];
            final double[] A_row = A[i];
            for (int j = 0; j < nC; j++) {
                for (int k = 0; k < nA; k++) {
                    C_row[j] += A_row[k] * B[k][j];
                }
            }
        }
        return C;
    }
}

Related

  1. matrix_x_vectorMatrix(double[][] mat, double[][] vector, int vectorCol)
  2. matrixAbsDiff(double m1[][], double m2[][])
  3. matrixATrans_x_matrixB(double[][] matA, double[][] matB)
  4. matrixConcatLR(double[][] LMatrix, double[][] RMatrix)