Hi All, I am using jama to calculate SVD. It work very good. If i pass square matrix. For example 2x2 or 3x3 etc. matrix. But when I pass some thing like this 2x3 or 4x8 it give error . I used all of their example. They have different constructor to perform the job. Also my second question is, I am usded 3x3 matrix and it gave
double[][] vals = {{1.,1.,0},{1.,0.,1.},{1.,3.,4.},{6.,4.,8.}};
Matrix A = new Matrix(vals);
It produced following error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
After that I thaught to use another constructor that is as follow
double[][] vals = {{1.,1.,0,4},{1.,0.,1.,2},{1.,3.,4.,8},{1.,3.,4.,8}};
Matrix A = new Matrix(vals,4,3);
It produced following output:
A =
1.0 1.0 0.0
1.0 0.0 1.0
1.0 3.0 4.0
6.0 4.0 8.0
A = U S V^T
U =
0.078 -0.115 -0.963
0.107 -0.281 0.260
0.402 0.886 -0.018
0.906 -0.351 0.060
Sigma =
11.861881 0.000000 0.000000
0.000000 2.028349 0.000000
0.000000 0.000000 1.087006
V =
0.507705 -0.795196 -0.331510
0.413798 0.562579 -0.715735
0.755650 0.226204 0.614675
rank = 3
condition number = 10.912437186202627
2-norm = 11.86188091889931
singular values =
11.861881 2.028349 1.087006
It worked for non square matrix. But it produced wrong results for svd because V and S doesn't have same rows=4 ( I am sorry if i couldn't analyze result properly as i am new for SVD) . Any idea? What should I do?