Пример #1
0
        /// <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>
        public static MatrixDefiniteness ComputeDefiniteness(this Matrix matrix)
        {
            Double[] eigenValues = QRDecomposition.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);
            }
        }
Пример #2
0
 /// <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(QRDecomposition.ComputeEigenvalues(matrix));
 }