Skip to content

Instantly share code, notes, and snippets.

@moomoohk
moomoohk / Mult.java
Last active December 30, 2015 02:09 — forked from anonymous/gist:7760387
// return C = A * B
public static double[][] multiply(double[][] A, double[][] B)
{
int mA = A.length; //row
int nA = A[0].length; //col
int mB = B.length;
int nB = A[0].length;
if (nA != mB)
throw new RuntimeException("Illegal matrix dimensions.");
double[][] C = new double[mA][nB];
public matrix mul(matrix B)
{
// Return a new matrix which is the matrix product of this
// with B.
if((rows()!=B.rows()) || (cols()!=B.cols()))
{
System.out.println("Error, cannot add since the 2 matrices do not have the same dimensions.");
System.exit(0);
}
matrix M = new matrix(rows(), cols());