예제 #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 specified matrix.
        /// </summary>
        /// <param name="matrix">The matrix.</param>
        /// <returns>The array containing the eigenvalues of the <paramref name="matrix" />.</returns>
        /// <exception cref="System.ArgumentNullException">The matrix is null.</exception>
        public static Double[] ComputeEigenvalues(Matrix matrix)
        {
            if (matrix == null)
            {
                throw new ArgumentNullException("matrix", "The matrix is null.");
            }

            Double[] eigenValues = new Double[matrix.NumberOfRows];

            QRDecomposition decomposition = new QRDecomposition(matrix);

            decomposition.Compute(10);

            for (int i = 0; i < matrix.NumberOfRows; ++i)
            {
                eigenValues[i] = decomposition.QR[i, i];
            }
            return(eigenValues);
        }
예제 #3
0
        /// <summary>
        /// Computes the eigenvectors of the specified matrix.
        /// </summary>
        /// <param name="matrix">The matrix.</param>
        /// <returns>The array containing the eigenvectors of the <paramref name="matrix" />.</returns>
        /// <exception cref="System.ArgumentNullException">The matrix is null.</exception>
        public static Vector[] ComputeEigenvectors(Matrix matrix)
        {
            if (matrix == null)
            {
                throw new ArgumentNullException("matrix", "The matrix is null.");
            }

            Vector[] eigenVectors = new Vector[matrix.NumberOfRows];

            QRDecomposition decomposition = new QRDecomposition(matrix);

            decomposition.Compute(2);

            for (int i = 0; i < matrix.NumberOfRows; ++i)
            {
                eigenVectors[i] = new Vector(matrix.NumberOfColumns);
                for (int j = 0; j < matrix.NumberOfColumns; ++j)
                {
                    eigenVectors[i][j] = decomposition.Q[i, j];
                }
            }

            return(eigenVectors);
        }
예제 #4
0
 /// <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(QRDecomposition.ComputeEigenvectors(matrix));
 }
예제 #5
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));
 }