The behavior of the SVD() method of GMatrix seems to conflict with that
  specified
  in the javax.vecmath section of the Java3D API:
  http://java.sun.com/products/java-media/3D/forDevelopers/J3D_1_2_API/j3dapi/index.html

  TestSVD3x3.java (see below) shows that GMatrix.SVD(U, W, V) does not
  overwrite W as the API says it should; U and V are overwritten and contain the
  correct values (I checked with matlab), except U is the transpose of what I think it
  should be based on the API.

I have also include short programs for a 2x2 matrix and a 4x4 matrix.  The 2x2 matrix produces a java.lang.ArrayIndexOutOfBoundsException when GMatrix.SVD is called, and the 4x4 matrix produces results for U and V that aren't the same as what I get from Matlab.

Am I using this method incorrectly?
 

//: TestSVD3x3.java
import javax.vecmath.*;

public class TestSVD3x3 {
  public static void main(String[] args) 
  {
    double[] arrayMat = { 1, 2, 0, 
                        3, 4, 0,
                        0, 0, 0 };

    GMatrix mat = new GMatrix(3, 3, arrayMat);

    System.out.println("The matrix is \n" + mat);

    GMatrix U = new GMatrix(3,3), W = new  GMatrix(3, 3), 
      V = new GMatrix(3, 3);

    int rank = mat.SVD(U, W, V);

    System.out.println("The rank of the matrix is " + rank + "\n");

    System.out.println("\nAfter SVD, U = \n" + U);

    System.out.println("\nAfter SVD, W = \n" + W);
    System.out.println("\nAfter SVD, V = \n" + V);
  }
}

//: TestSVD2x2.java
import javax.vecmath.*;

public class TestSVD2x2 {
  public static void main(String[] args) 
  {
    double[] arrayMat = { 1, 2, 
                          3, 4 };
                       
    GMatrix mat = new GMatrix(2, 2, arrayMat);

    System.out.println("The matrix is \n" + mat);

    GMatrix U = new GMatrix(2,2), W = new  GMatrix(2, 2), 
      V = new GMatrix(2, 2);

    int rank = mat.SVD(U, W, V);

    System.out.println("The rank of the matrix is " + rank + "\n");

    System.out.println("\nAfter SVD, U = \n" + U);

    System.out.println("\nAfter SVD, W = \n" + W);
    System.out.println("\nAfter SVD, V = \n" + V);
  }
}

 
//: TestSVD4x4.java
import javax.vecmath.*;

public class TestSVD4x4 {
  public static void main(String[] args) 
  {
    double[] arrayMat = { 1, 2, 3, 4, 
                          5, 6, 7, 8,
                          9, 10, 11, 12,
                          13, 14, 15, 16 };

    GMatrix mat = new GMatrix(4, 4, arrayMat);

    System.out.println("The matrix is \n" + mat);

    GMatrix U = new GMatrix(4,4), W = new  GMatrix(4, 4), 
      V = new GMatrix(4, 4);

    int rank = mat.SVD(U, W, V);

    System.out.println("The rank of the matrix is " + rank + "\n");

    System.out.println("\nAfter SVD, U = \n" + U);

    System.out.println("\nAfter SVD, W = \n" + W);
    System.out.println("\nAfter SVD, V = \n" + V);
  }
}

 
 

Reply via email to