Пример #1
0
        /// <summary>
        /// Example program that illustrates how to solve a nonsymmetric generalized eigenvalue
        /// problem in complex shift and invert mode (taking the real part of OP*x).
        /// </summary>
        /// <remarks>
        /// MODULE LNSymGSC.cc
        ///
        /// In this example we try to solve A*x = B*x*lambda in complex shift and inverse mode,
        /// where A is the tridiagonal matrix with 2 on the diagonal, -2 on the subdiagonal and
        /// 3 on the superdiagonal, and B is the tridiagonal matrix with 4 on the diagonal and
        /// 1 on the off-diagonals. The shift is a complex number.
        ///
        /// The SuperLU package is called to solve some complex linear systems involving (A-sigma*B).
        /// </remarks>
        static void LNSymGSC()
        {
            int n = 100; // Dimension of the problem.

            // Creating matrices A and B.
            var A = Generate.NonSymMatrixE(n);
            var B = Generate.NonSymMatrixF(n);

            // Defining what we need: the four eigenvectors nearest to 0.4 + 0.6i.
            var prob = new Arpack(A, B)
            {
                ComputeEigenVectors = true
            };

            // Finding eigenvalues and eigenvectors.
            var result = prob.SolveGeneralized(4, 0.4, 0.6, 'R');

            // Printing solution.
            Solution.General(A, B, (ArpackResult)result, true, true);
        }
Пример #2
0
        /// <summary>
        /// Example program that illustrates how to solve a real symmetric generalized eigenvalue
        /// problem in Cayley mode.
        /// </summary>
        /// <remarks>
        /// MODULE LSymGCay.cc
        ///
        /// In this example we try to solve A*x = B*x*lambda in Cayley mode, where A and B are obtained
        /// from the finite element discretization of the 1-dimensional discrete Laplacian
        ///                               d^2u / dx^2
        ///  on the interval [0,1] with zero Dirichlet boundary conditions using piecewise linear elements.
        ///
        /// The SuperLU package is called to solve some linear systems involving (A-sigma*B).
        /// </remarks>
        static void LSymGCay()
        {
            int n = 100; // Dimension of the problem.

            // Creating matrices A and B.
            var A = Generate.SymmetricMatrixC(n);
            var B = Generate.SymmetricMatrixD(n);

            // Defining what we need: the four eigenvectors nearest to 150.0.
            var prob = new Arpack(A, B, true)
            {
                ComputeEigenVectors = true
            };

            // Finding eigenvalues and eigenvectors.
            var result = prob.SolveGeneralized(4, 150.0, ShiftMode.Cayley);

            // Printing solution.
            Solution.Symmetric(A, B, (ArpackResult)result, ShiftMode.Cayley);
        }
Пример #3
0
        /// <summary>
        /// Example program that illustrates how to solve a real symmetric generalized eigenvalue
        /// problem in regular mode.
        /// </summary>
        /// <remarks>
        /// MODULE LSymGReg.cc
        ///
        /// In this example we try to solve A*x = B*x*lambda in regular mode, where A and B are obtained
        /// from the finite element discretization of the 1-dimensional discrete Laplacian
        ///                               d^2u / dx^2
        /// on the interval [0,1] with zero Dirichlet boundary conditions using piecewise linear elements.
        ///
        /// The SuperLU package is called to solve some linear systems involving B.
        /// </remarks>
        static void LSymGReg()
        {
            int n = 100; // Dimension of the problem.

            // Creating matrices A and B.
            var A = Generate.SymmetricMatrixC(n);
            var B = Generate.SymmetricMatrixD(n);

            // Defining what we need: the four eigenvectors with largest magnitude.
            var prob = new Arpack(A, B, true)
            {
                ComputeEigenVectors = true
            };

            // Finding eigenvalues and eigenvectors.
            var result = prob.SolveGeneralized(4, Spectrum.LargestMagnitude);

            // Printing solution.
            Solution.Symmetric(A, B, (ArpackResult)result, ShiftMode.None);
        }
Пример #4
0
        /// <summary>
        /// Example program that illustrates how to solve a real nonsymmetric generalized eigenvalue
        /// problem in real shift and invert mode.
        /// </summary>
        /// <remarks>
        /// MODULE LNSymGSh.cc
        ///
        /// In this example we try to solve A*x = B*x*lambda in shift and inverse mode, where A and B
        /// are derived from the finite element 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 using linear elements.
        /// The shift sigma is a real number.
        ///
        /// The SuperLU package is called to solve some linear systems involving (A-sigma*B).
        /// </remarks>
        static void LNSymGSh()
        {
            int    n   = 100;  // Dimension of the problem.
            double rho = 10.0; // A parameter used in StiffnessMatrix.

            // Creating matrices A and B.
            var A = Generate.StiffnessMatrix(n, rho);
            var B = Generate.MassMatrix(n);

            // Defining what we need: the four eigenvectors nearest to 1.0.
            var prob = new Arpack(A, B)
            {
                ComputeEigenVectors = true
            };

            // Finding eigenvalues and eigenvectors.
            var result = prob.SolveGeneralized(4, 1.0);

            // Printing solution.
            Solution.General(A, B, (ArpackResult)result, true);
        }
Пример #5
0
        /// <summary>
        /// Example program that illustrates how to solve a complex generalized eigenvalue
        /// problem in regular mode.
        /// </summary>
        /// <remarks>
        /// MODULE LCompGRe.cc
        ///
        /// In this example we try to solve A*x = B*x*lambda in regular mode, where A and B are
        /// derived from the finite element discretization of the 1-dimensional convection-diffusion
        /// operator
        ///                    (d^2u/dx^2) + rho*(du/dx)
        ///
        /// on the interval [0,1], with zero boundary conditions, using piecewise linear elements.
        /// </remarks>
        static void LCompGRe()
        {
            int n = 100; // Dimension of the problem.

            Complex rho = 10.0;

            // Creating complex matrices A and B.
            var A = Generate.CompMatrixE(n, rho);
            var B = Generate.CompMatrixF(n);

            // Defining what we need: the four eigenvectors with largest magnitude.
            var dprob = new Arpack(A, B)
            {
                ComputeEigenVectors = true
            };

            // Finding eigenvalues and eigenvectors.
            var result = dprob.SolveGeneralized(4, Spectrum.LargestMagnitude);

            // Printing solution.
            Solution.Print(A, B, (ArpackResult)result, false);
        }
Пример #6
0
        /// <summary>
        /// Example program that illustrates how to solve a complex generalized eigenvalue
        /// problem in shift and invert mode.
        /// </summary>
        /// <remarks>
        /// MODULE LCompGSh.cc
        ///
        /// In this example we try to solve A*x = B*x*lambda in shift and invert mode, where A and B
        /// are derived from a finite element discretization of a 1-dimensional convection-diffusion
        /// operator
        ///                      (d^2u/dx^2) + rho*(du/dx)
        ///
        /// on the interval [0,1], with zero boundary conditions, using piecewise linear elements.
        /// </remarks>
        static void LCompGSh()
        {
            int n = 100; // Dimension of the problem.

            Complex rho = 10.0;

            // Creating complex matrices A and B.
            var A = Generate.CompMatrixE(n, rho);
            var B = Generate.CompMatrixF(n);

            // Defining what we need: the four eigenvectors nearest to sigma.

            var dprob = new Arpack(A, B)
            {
                ComputeEigenVectors = true
            };

            // Finding eigenvalues and eigenvectors.
            var result = dprob.SolveGeneralized(4, new Complex(1.0, 0.0));

            // Printing solution.
            Solution.Print(A, B, (ArpackResult)result, true);
        }