Search in sources :

Example 6 with RationalMatrixFast

use of cbit.vcell.matrix.RationalMatrixFast in project vcell by virtualcell.

the class SVDTest method findNullSpaceSVD.

/**
 * Insert the method's description here.
 * Creation date: (5/13/2003 4:37:34 PM)
 * @param matrix Jama.Matrix
 */
public static RationalMatrix findNullSpaceSVD(RationalMatrix rA) {
    try {
        Jama.Matrix A = getJamaMatrix(rA);
        Jama.Matrix At = A.transpose();
        Jama.SingularValueDecomposition svdMatrix = new Jama.SingularValueDecomposition(At);
        Jama.Matrix U = svdMatrix.getU();
        Jama.Matrix V = svdMatrix.getV();
        double[] S = svdMatrix.getSingularValues();
        // System.out.println("A' = U*S*V'");
        // System.out.println("A' = ");
        // At.print(8,5);
        // System.out.println("U = ");
        // U.print(8,5);
        // System.out.println("V = ");
        // V.print(8,5);
        // System.out.print("S = ");
        // for (int i = 0; i < S.length; i++){
        // System.out.print(S[i]+" ");
        // }
        // System.out.println();
        int rank = svdMatrix.rank();
        // System.out.println("rank = "+rank);
        Jama.Matrix Vt = V.transpose();
        Jama.Matrix nsMatrix = Vt.getMatrix(rank, Vt.getRowDimension() - 1, 0, Vt.getColumnDimension() - 1);
        // System.out.println("NS = ");
        // nsMatrix.print(8,5);
        SimpleMatrix matrix = new SimpleMatrix(nsMatrix.getArrayCopy());
        // matrix.show();
        SimpleMatrix.gaussianElimination(new SimpleMatrix(matrix.getNumRows(), matrix.getNumRows()), matrix);
        // matrix.show();
        RationalMatrixFast nsRationalMatrix = getRationalMatrixFast(matrix);
        // nsRationalMatrix.show();
        return nsRationalMatrix;
    } catch (Throwable e) {
        e.printStackTrace(System.out);
        throw new RuntimeException(e.getMessage());
    }
}
Also used : SimpleMatrix(cbit.vcell.matrix.SimpleMatrix) RationalMatrixFast(cbit.vcell.matrix.RationalMatrixFast)

Aggregations

RationalMatrixFast (cbit.vcell.matrix.RationalMatrixFast)6 SimpleMatrix (cbit.vcell.matrix.SimpleMatrix)3 RationalNumber (cbit.vcell.matrix.RationalNumber)2