Java Matrix Product matrixProduct(double[][] m, double[][] n)

Here you can find the source of matrixProduct(double[][] m, double[][] n)

Description

matrix Product

License

Open Source License

Declaration

public static double[][] matrixProduct(double[][] m, double[][] n) throws Exception 

Method Source Code

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

public class Main {
    public static double[][] matrixProduct(double[][] m, double[][] n) throws Exception {
        if (m[0].length != n.length)
            throw new Exception("Can't do the requested product");

        double[][] p = new double[m.length][n.length];
        for (int i = 0; i < m.length; i++) {
            for (int j = 0; j < n[0].length; j++) {
                p[i][j] = pointProduct(m[i], getColumn(n, j));
            }/*  ww w  . j a  v  a 2  s. co m*/
        }
        return p;
    }

    public static double pointProduct(double[] m, double[] n) throws Exception {
        if (m.length != n.length)
            throw new Exception("Can't do the requested product");
        double acum = 0;
        for (int i = 0; i < n.length; i++) {
            acum += m[i] * n[i];
        }
        return acum;
    }

    public static double[] getColumn(double[][] m, int j) {
        double[] column = new double[m.length];
        for (int i = 0; i < column.length; i++) {
            column[i] = m[i][j];
        }
        return column;
    }
}

Related

  1. matrix_vector_product(double[][] a, double[] v)
  2. matrixInnerProduct(int M, int N, double m1[][], double m2[][])
  3. matrixProduct(double[][] A, double[][] B)
  4. matrixProduct(double[][] x, double[] y)
  5. matrixProductVDVT(final double[][] V, final double[] d, final double[][] A, int n)
  6. product(final T[][] args)