我正在使用 jama 库作为矩阵。我使用了以下矩阵,但是当我尝试获取 S 时,它给了我错误。
1.0 1.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 11.0 1.0
1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 12.0 2.0
1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 13.0 3.0
当我尝试获取 S 时,它会产生以下错误。
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at Jama.SingularValueDecomposition.getS(SingularValueDecomposition.java:507)
at SVD2.main(SVD2.java:19)
这是代码
public class SVD2 {
public static void main(String[] args) {
double[][] vals = {
{1,1,0,1,0,0,0,0,0,11,1},
{1,0,0,0,0,0,1,0,0,12,2},
{1,1,0,0,0,0,0,0,1,13,3}
};
Matrix A = new Matrix(vals,3,11);
System.out.println("The Matrix A is ");
A.print(11, 2);
System.out.println();
System.out.println("The SVD of A is ");
SingularValueDecomposition svd = A.svd();
Matrix S = svd.getS();
}
}