0

我正在尝试使用 ejml 库对矩阵进行 LU 分解。SVD分解的计算一切顺利,对于LU分解我不知道使用ejml库。我需要你的帮助

import java.util.Scanner;
import org.ejml.alg.dense.decomposition.CholeskyDecomposition;
import org.ejml.alg.dense.decomposition.DecompositionFactory;
import org.ejml.alg.dense.decomposition.DecompositionInterface; 
import org.ejml.alg.dense.decomposition.LUDecomposition;
import org.ejml.alg.dense.decomposition.lu.*;
import org.ejml.data.DenseMatrix64F;
import org.ejml.simple.SimpleMatrix;
import org.ejml.simple.SimpleSVD;


public class autovalori {
public static void main(String[] args) {


double[][] matrix;
double[] u;
int r, c, t = 0;


Scanner scanner = new Scanner(System.in);

System.out.println("Insert row matrix: ");
r = scanner.nextInt();//row matrix
System.out.println("Insert columns matrix: ");
c =  scanner.nextInt(); //columns matrix
matrix = new double[r][c];



    for (int i = 0; i < r; i++){
         for (int j = 0; j < c; j++){

             System.out.printf("value: " + i + " - " + j);
             System.out.printf("\n");
             matrix[i][j] = scanner.nextDouble();

         }
     }

    System.out.printf("\n");


    SimpleMatrix A = new SimpleMatrix(matrix);

    SimpleSVD SVD = A.svd();
    SimpleMatrix U = SVD.getU();
    SimpleMatrix S = SVD.getV();
    SimpleMatrix V = SVD.getW();

    U.print();
    S.print();
    V.print();
4

1 回答 1

1

SimpleMatrix 接口不提供计算 LU 分解的直接方法。相反,您需要从分解算法中计算它。

    SimpleMatrix A = new SimpleMatrix(10,5);

    LUDecomposition<DenseMatrix64F> lu = DecompositionFactory.lu(A.numCols());

    if( !lu.decompose(A.getMatrix()) ) {
        throw new RuntimeException("LU Decomposition failed!");
    }

    SimpleMatrix L = SimpleMatrix.wrap(lu.getLower(null));
    SimpleMatrix U = SimpleMatrix.wrap(lu.getUpper(null));
于 2012-06-07T18:35:46.530 回答