Beispiel #1
0
        /// <summary>
        /// Computes the eigenvectors of the specified matrix.
        /// </summary>
        /// <param name="matrix">The matrix.</param>
        /// <param name="numberOfIterations">The number of iterations.</param>
        /// <returns>The collection containing the eigenvectors of the <paramref name="matrix" />.</returns>
        /// <exception cref="System.ArgumentNullException">The matrix is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">The number of iterations is less than 1.</exception>
        public static Vector[] ComputeEigenvectors(Matrix matrix, Int32 numberOfIterations)
        {
            QRAlgorithm algorithm = new QRAlgorithm(matrix);

            algorithm.Compute(numberOfIterations);

            return(algorithm.Eigenvectors);
        }
Beispiel #2
0
        /// <summary>
        /// Computes the eigenvectors of the specified matrix.
        /// </summary>
        /// <param name="matrix">The matrix.</param>
        /// <returns>The collection containing the eigenvectors of the <paramref name="matrix" />.</returns>
        /// <exception cref="System.ArgumentNullException">The matrix is null.</exception>
        public static Vector[] ComputeEigenvectors(Matrix matrix)
        {
            QRAlgorithm algorithm = new QRAlgorithm(matrix);

            algorithm.Compute();

            return(algorithm.Eigenvectors);
        }
Beispiel #3
0
        /// <summary>
        /// Computes the eigenvalues of the specified matrix.
        /// </summary>
        /// <param name="matrix">The matrix.</param>
        /// <param name="numberOfIterations">The number of iterations.</param>
        /// <returns>The collection containing the eigenvalues of the <paramref name="matrix" />.</returns>
        /// <exception cref="System.ArgumentNullException">The matrix is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">The number of iterations is less than 1.</exception>
        public static Double[] ComputeEigenvalues(Matrix matrix, Int32 numberOfIterations)
        {
            QRAlgorithm algorithm = new QRAlgorithm(matrix);

            algorithm.Compute(numberOfIterations);

            return(algorithm.Eigenvalues);
        }
Beispiel #4
0
        /// <summary>
        /// Computes the eigenvalues of the specified matrix.
        /// </summary>
        /// <param name="matrix">The matrix.</param>
        /// <returns>The collection containing the eigenvalues of the <paramref name="matrix" />.</returns>
        /// <exception cref="System.ArgumentNullException">The matrix is null.</exception>
        public static Double[] ComputeEigenvalues(Matrix matrix)
        {
            QRAlgorithm algorithm = new QRAlgorithm(matrix);

            algorithm.Compute();

            return(algorithm.Eigenvalues);
        }
 /// <summary>
 /// Computes the eigenvectors of the matrix.
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 /// <returns>The eigenvectors of the matrix.</returns>
 /// <exception cref="System.ArgumentNullException">The matrix is null.</exception>
 public static Vector[] Eigenvectors(this Matrix matrix)
 {
     return(QRAlgorithm.ComputeEigenvectors(matrix));
 }
 /// <summary>
 /// Computes the eigenvalues of the matrix.
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 /// <returns>The eigenvalues of the matrix.</returns>
 /// <exception cref="System.ArgumentNullException">The matrix is null.</exception>
 public static Double[] Eigenvalues(this Matrix matrix)
 {
     return(QRAlgorithm.ComputeEigenvalues(matrix));
 }
        /// <summary>
        /// Computes the definiteness of the matrix.
        /// </summary>
        /// <param name="matrix">The matrix.</param>
        /// <returns>The definiteness of the matrix.</returns>
        /// <exception cref="System.ArgumentNullException">The matrix is null.</exception>
        /// <exception cref="System.ArgumentException">
        /// The matrix is empty.
        /// or
        /// The matrix is not symmetric.
        /// </exception>
        public static MatrixDefiniteness Definiteness(this Matrix matrix)
        {
            if (matrix == null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            if (matrix.NumberOfRows == 0 && matrix.NumberOfColumns == 0)
            {
                throw new ArgumentException(NumericsMessages.MatrixIsEmpty, nameof(matrix));
            }

            if (!IsSymmetric(matrix))
            {
                throw new ArgumentException(NumericsMessages.MatrixIsNotSymmetric, nameof(matrix));
            }

            if (matrix.All(value => value == 0))
            {
                return(MatrixDefiniteness.PositiveSemidefinite);
            }

            Double[] eigenvalues = QRAlgorithm.ComputeEigenvalues(matrix);
            Int32    posValues   = 0;
            Int32    negValues   = 0;
            Int32    zeroValues  = 0;

            for (Int32 index = 0; index < eigenvalues.Length; ++index)
            {
                if (eigenvalues[index] > 0)
                {
                    posValues++;
                }
                else if (eigenvalues[index] < 0)
                {
                    negValues++;
                }
                else
                {
                    zeroValues++;
                }
            }

            if (posValues > 0 && negValues == 0 && zeroValues == 0)
            {
                return(MatrixDefiniteness.PositiveDefinite);
            }
            else if (negValues > 0 && posValues == 0 && zeroValues == 0)
            {
                return(MatrixDefiniteness.NegativeDefinite);
            }
            else if (posValues > 0 && zeroValues > 0 && negValues == 0)
            {
                return(MatrixDefiniteness.PositiveSemidefinite);
            }
            else if (negValues > 0 && zeroValues > 0 && posValues == 0)
            {
                return(MatrixDefiniteness.NegativeSemiDefinite);
            }
            else
            {
                return(MatrixDefiniteness.Indefinite);
            }
        }