public void Run(SparseMatrix A, int m, bool symmetric) { // For real symmetric problems, ARPACK++ expects the matrix to be upper triangular. var U = A.ToUpper(); var solver = new Arpack(U, symmetric) { Tolerance = 1e-6, ComputeEigenVectors = true }; var timer = Stopwatch.StartNew(); var result = solver.SolveStandard(m, 0.0); //var result = solver.SolveStandard(m, Spectrum.SmallestMagnitude); //var result = solver.SolveStandard(m, 8.0); //var result = solver.SolveStandard(m, Spectrum.LargestMagnitude); timer.Stop(); Display.Time(timer.ElapsedTicks); result.EnsureSuccess(); if (Helper.CheckResiduals(A, result, symmetric, false)) { Display.Ok("OK"); } else { Display.Warning("residual error too large"); } }
/// <summary> /// Example program that illustrates how to solve a real symmetric standard eigenvalue /// problem in shift and invert mode. /// </summary> /// <remarks> /// MODULE LSymShf.cc /// /// In this example we try to solve A*x = x*lambda in shift and invert mode, where A is /// derived from the central difference discretization of the one-dimensional Laplacian /// on [0, 1] with zero Dirichlet boundary conditions. /// /// The SuperLU package is called to solve some linear systems involving (A-sigma*I). /// This is needed to implement the shift and invert strategy. /// </remarks> static void LSymShf() { int n = 100; // Dimension of the problem. // Creating a 100x100 matrix. var A = Generate.SymmetricMatrixB(n); // Defining what we need: the four eigenvectors of A nearest to 1.0. var prob = new Arpack(A, true) { ComputeEigenVectors = true }; // Finding eigenvalues and eigenvectors. var result = prob.SolveStandard(4, 1.0); // Printing solution. Solution.Symmetric(A, (ArpackResult)result, true); }
/// <summary> /// Example program that illustrates how to solve a real symmetric standard eigenvalue /// problem in regular mode. /// </summary> /// <remarks> /// MODULE LSymReg.cc /// /// In this example we try to solve A*x = x*lambda in regular mode, where A is derived /// from the standard central difference discretization of the 2-dimensional Laplacian /// on the unit square with zero Dirichlet boundary conditions. /// </remarks> static void LSymReg() { int nx = 10; // Creating a 100x100 matrix. var A = Generate.SymmetricMatrixA(nx); // Defining what we need: the four eigenvectors of A with smallest magnitude. var prob = new Arpack(A, true) { ComputeEigenVectors = true }; // Finding eigenvalues and eigenvectors. var result = prob.SolveStandard(2, Spectrum.SmallestMagnitude); // Printing solution. Solution.Symmetric(A, (ArpackResult)result, false); }
/// <summary> /// Example program that illustrates how to solve a real nonsymmetric standard eigenvalue /// problem in shift and invert mode. /// </summary> /// <remarks> /// MODULE LNSymShf.cc /// /// In this example we try to solve A*x = x*lambda in shift and invert mode, where A is /// derived from 2-D Brusselator Wave Model. The shift is a real number. /// /// The SuperLU package is called to solve some linear systems involving (A-sigma*I). /// </remarks> static void LNSymShf() { int n = 200; // Dimension of the problem. // Creating a 200x200 matrix. var A = Generate.BrusselatorMatrix(1.0, 0.004, 0.008, 2.0, 5.45, n); // Defining what we need: the four eigenvectors of BWM nearest to 0.0. var prob = new Arpack(A) { ComputeEigenVectors = true, ArnoldiCount = 30 }; // Finding eigenvalues and eigenvectors. var result = prob.SolveStandard(4, 0.0, Spectrum.LargestMagnitude); // Printing solution. Solution.General(A, (ArpackResult)result, true); }
/// <summary> /// Example program that illustrates how to solve a real nonsymmetric standard eigenvalue /// problem in regular mode. /// </summary> /// <remarks> /// MODULE LNSymReg.cc /// /// In this example we try to solve A*x = x*lambda in regular mode, where A is derived from /// the standard central difference discretization of the 2-dimensional convection-diffusion /// operator /// (Laplacian u) + rho*(du/dx) /// on a unit square with zero Dirichlet boundary conditions. /// </remarks> static void LNSymReg() { int nx = 10; // Creating a 100x100 matrix. var A = Generate.BlockTridMatrix(nx); // Defining what we need: the four eigenvectors of A with largest magnitude. var prob = new Arpack(A) { ComputeEigenVectors = true }; // Finding eigenvalues and eigenvectors. var result = prob.SolveStandard(4, Spectrum.LargestMagnitude); // Printing solution. Solution.General(A, (ArpackResult)result, false); }
/// <summary> /// Example program that illustrates how to solve a complex standard eigenvalue /// problem in regular mode. /// </summary> /// <remarks> /// MODULE LCompReg.cc /// /// In this example we try to solve A*x = x*lambda in regular mode, where A is obtained /// from the standard central difference discretization of the convection-diffusion /// operator /// (Laplacian u) + rho*(du / dx) /// /// on the unit square [0,1]x[0,1] with zero Dirichlet boundary conditions. /// </remarks> static void LCompReg() { int nx = 10; // Dimension of the problem nx * nx. // Creating a complex matrix. var A = Generate.CompMatrixA(nx); // Defining what we need: the four eigenvectors of A with largest magnitude. var dprob = new Arpack(A) { ComputeEigenVectors = true }; // Finding eigenvalues and eigenvectors. var result = dprob.SolveStandard(2, Spectrum.LargestMagnitude); // Printing solution. Solution.Print(A, (ArpackResult)result, false); }
/// <summary> /// Example program that illustrates how to solve a complex standard eigenvalue /// problem in shift and invert mode. /// </summary> /// <remarks> /// MODULE LCompShf.cc /// /// In this example we try to solve A*x = x*lambda in shift and invert mode, where /// A is derived from the central difference discretization of the 1-dimensional /// convection-diffusion operator /// /// (d^2u/dx^2) + rho*(du/dx) /// /// on the interval [0,1] with zero Dirichlet boundary conditions. /// </remarks> static void LCompShf() { int n = 100; // Dimension of the problem. Complex rho = 10.0; // Creating a complex matrix. var A = Generate.CompMatrixB(n, rho); // Defining what we need: the four eigenvectors of F nearest to 0.0. var dprob = new Arpack(A) { ComputeEigenVectors = true }; // Finding eigenvalues and eigenvectors. var result = dprob.SolveStandard(4, new Complex(0.0, 0.0)); // Printing solution. Solution.Print(A, (ArpackResult)result, true); }