And what exactly are the results you are getting?



On Fri, Feb 14, 2014 at 6:07 PM, Patrick Meyer <meyer...@gmail.com> wrote:

> Hi,
>
>
>
> I am using the SingularValueDecomposition class with a matrix but it gives
> me a different result than R. My knowledge of SVD is limited, so any advice
> is welcomed.
>
>
>
> Here's the method in Java
>
>
>
> public void svdTest(){
>
>
>
>         double[][] x = {
>
>                 {1.0,  -0.053071807862720116,  0.04236086650321309},
>
>                 {0.05307180786272012,  1.0,  0.0058054424137053435},
>
>                 {-0.04236086650321309,  -0.005805442413705342,  1.0}
>
>         };
>
>
>
>         RealMatrix X = new Array2DRowRealMatrix(x);
>
>
>
>         SingularValueDecomposition svd = new SingularValueDecomposition(X);
>
>
>
>         RealMatrix U = svd.getU();
>
>         for(int i=0;i<U.getRowDimension();i++){
>
>             for(int j=0;j<U.getColumnDimension();j++){
>
>                 System.out.print(U.getEntry(i,j) + "  ");
>
>             }
>
>             System.out.println();
>
>         }
>
>
>
>         System.out.println();
>
>         System.out.println();
>
>         RealMatrix V = svd.getV();
>
>         for(int i=0;i<V.getRowDimension();i++){
>
>             for(int j=0;j<V.getColumnDimension();j++){
>
>                 System.out.print(V.getEntry(i,j) + "  ");
>
>             }
>
>             System.out.println();
>
>         }
>
>
>
>
>
>     }
>
>
>
>
>
> And here's the function in R.
>
>
>
> x<-matrix(c(
>
>                 1.0,  -0.053071807862720116,  0.04236086650321309,
>
>       0.05307180786272012,  1.0,  0.0058054424137053435,
>
>       -0.04236086650321309,  -0.005805442413705342,  1.0),
>
>                 nrow=3, byrow=TRUE)
>
> svd(x)
>
>
>
> Does anyone know why I am getting different results for U and V? I am using
> commons math 3.1.
>
>
>
> Thanks,
>
> Patrick
>
>
>
>
>
>
>
>

Reply via email to