public double[][] LUDecomposition(double[][] matrix) {
        int n = matrix.length;
        // Luodaan ja alustetaan matriisit L ja U.
        double[][] matrixL = new double[n][n];
        double[][] matrixU = new double[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                matrixL[i][j] = 0;
                matrixU[i][j] = 0;
                if (i == j) {
                    matrixL[i][j] = 1;
                }
            }
        }
        // Lasketaan hajotelma L- ja U-matriiseihin syötematriisin avulla.
        for (int k = 0; k < n; k++) {
            Double luku = Double.valueOf(matrix[k][k]);
            matrixU[k][k] = Double.valueOf(luku);
            for (int i = k + 1; i < n; i++) {
                matrixL[k][i] = matrix[k][i] / matrixU[k][k];
                Double luku2 = Double.valueOf(matrix[i][k]);
                matrixU[i][k] = Double.valueOf(luku2);
            }
            for (int i = k + 1; i < n; i++) {
                for (int j = k + 1; j < n; j++) {
                    matrix[j][i] = matrix[j][i] - matrixL[k][i] * matrixU[j][k];
                }
            }
        }
        // Palautetaan hajotelman algoritmin tuottama U-matriisi.
        return matrixU;
    }