private static JamaMatrix PseudoInverseBySVD(JamaMatrix gm) { if (gm.RowDimension < gm.ColumnDimension) { JamaMatrix gm2 = gm.transpose(); JamaMatrix jamaMatrix = PolynomialImageTransformer.PseudoInverseBySVD(gm2); return jamaMatrix.transpose(); } if (gm.RowDimension == gm.ColumnDimension) { return gm.inverse(); } SingularValueDecomposition singularValueDecomposition = new SingularValueDecomposition(gm); JamaMatrix jamaMatrix2 = singularValueDecomposition.S.transpose(); for (int i = 0; i < jamaMatrix2.RowDimension; i++) { double element = jamaMatrix2.GetElement(i, i); if (element != 0.0) { jamaMatrix2.SetElement(i, i, 1.0 / element); } } return singularValueDecomposition.getV().times(jamaMatrix2).times(singularValueDecomposition.getU().transpose()); }