Here you can find the source of matrixProduct(double[][] m, double[][] n)
public static double[][] matrixProduct(double[][] m, double[][] n) throws Exception
//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; } }