private double[][] multiplyMatrices(double[][] L, double[][] R) {
        int m = L[0].length;
        int n = R[1].length;

        // Matrices must have agreeing inner dimensions
        if (L[0].length != R.length) {
            throw new IllegalArgumentException();
        }

        // Initialize return matrix
        double[][] ret = new double[m][n];

        // Matrix multiplication algorithm
        for (int i = 0; i < m; i++) {
            for (int j = 0; j< n; j++) {
                for (int k = 0; k < R.length; k++) {
                    ret[i][j] += L[i][k] * R[k][j];
                }
            }
        }
        return ret;
    }