public static double[][] mul(double[][] m1, double[][] m2)
			throws MatrixException {

		int m1Len = m1.length;
		int m2Len = m2.length;

		if (m1Len == 0 || m2Len == 0) {
			throw new MatrixException("Incompatible Matrices");
		} else if (m1[0].length == 0 || m2[0].length == 0) {
			throw new MatrixException("Incompatible Matrices");
		} else if (m1[0].length != m2.length) {
			throw new MatrixException(
					"Incompatible Matrices for multiplication");
		}

		int m1Width = m1[0].length;
		int m2Width = m2[0].length;

		double[][] res = new double[m1Len][m2Width];

		double val = 0;
		for (int i = 0; i < m1Len; i++) {
			for (int j = 0; j < m2Width; j++) {
				val = 0;
				for (int k = 0; k < m1Width; k++) {
					val += m1[i][k] * m2[k][j];
				}
				res[i][j] = val;
			}
		}
		return res;
	}