Java Array Multiply mult(double[][] A, double[][] B)

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

Description

mult

License

Creative Commons License

Declaration

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

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

import java.util.Arrays;

public class Main {
    public static double[][] mult(double[][] A, double[][] B) {

        if (A.length != B.length)
            throw new IllegalArgumentException("dim A != dim B");

        double[][] AB = buildZeroMatrix(A.length);

        for (int i = 0; i < A.length; i++) {
            for (int j = 0; j < A.length; j++) {
                AB[i][j] = 0;//w w  w  . j a  va2  s.  c om
                for (int k = 0; k < A.length; k++) {
                    AB[i][j] += A[i][k] * B[k][j];
                }
            }
        }
        return AB;

    }

    /**
     * 
     * @return zero matrix of m*m size
     */
    public static double[][] buildZeroMatrix(int m) {

        double[][] matrix = new double[m][m];

        for (int index = 0; index < m; index++)
            Arrays.fill(matrix[index], 0);

        return matrix;

    }
}

Related

  1. mult(float[] nums, float n)
  2. mult(float[] nums, float n)
  3. multiply(byte[] a, byte b)
  4. multiply(double factor, double[] vector)