/// <summary> /// Example program that illustrates how to determine the condition number of a matrix /// to find its largest and smallest singular values. /// </summary> /// <remarks> /// MODULE LSVD.cc /// /// In this example, Arpack++ is called to solve the symmetric problem: /// /// (A'*A)*v = sigma*v /// /// where A is an m by n real matrix. This formulation is appropriate when m >= n. /// The roles of A and A' must be reversed in the case that m < n. /// </remarks> private static void LSVDcond() { // Number of columns in A. int n = 100; // Creating a rectangular matrix with m = 200 and n = 100. var A = Generate.RectangularMatrix(n); int m = A.RowCount; // Number of rows in A. // Defining what we need: eigenvalues from both ends of the spectrum. var prob = new Arpack(A) { ArnoldiCount = 20 }; // Finding eigenvalues. var result = prob.SingularValues(6, true, Spectrum.BothEnds); Solution.Condition(A, (ArpackResult)result); }
/// <summary> /// Example program that illustrates how to determine the truncated SVD of a matrix. /// </summary> /// <remarks> /// MODULE LSVD.cc /// /// In this example, Arpack++ is called to solve the symmetric problem: /// /// | 0 A |*y = sigma*y, /// | A' 0 | /// /// where A is an m by n real matrix. /// /// This problem can be used to obtain the decomposition A = U*S*V'. The positive /// eigenvalues of this problem are the singular values of A (the eigenvalues come /// in pairs, the negative eigenvalues have the same magnitude of the positive ones /// and can be discarded). The columns of U can be extracted from the first m /// components of the eigenvectors y, while the columns of V can be extracted from /// the the remaining n components. /// </remarks> private static void LSVDpart() { // Number of columns in A. int n = 100; // Creating a rectangular matrix with m = 200 and n = 100. var A = Generate.RectangularMatrix(n); int m = A.RowCount; // Number of rows in A. // Defining what we need: the four eigenvalues with largest algebraic value. var prob = new Arpack(A) { ArnoldiCount = 20, ComputeEigenVectors = true }; // Finding eigenvalues. var result = prob.SingularValues(5, false, Spectrum.LargestAlgebraic); // Printing the solution. Solution.SVD(A, (ArpackResult)result); }