Пример #1
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);
        }
Пример #2
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);
        }