/// <summary> /// Computes all eigenvalues of a real symmetric matrix A. /// </summary> /// <param name="A">The real symmetric matrix A.</param> /// <returns>The eigenvalues.</returns> public Matrix GetEigenvalues(SymmetricMatrix A) { if (this._dsyev == null) { this._dsyev = new DSYEV(); } this.CheckDimensions(A); Matrix EigenVects = new Matrix(A.RowCount, A.ColumnCount, A.Data); double[] EigenVectsData = EigenVects.Data; Matrix EigenVals = new Matrix(A.RowCount, 1); double[] EigenValsData = EigenVals.Data; int Info = 0; double[] Work = new double[1]; int LWork = -1; //Calculamos LWORK ideal _dsyev.Run("N", "U", A.RowCount, ref EigenVectsData, 0, A.RowCount, ref EigenValsData, 0, ref Work, 0, LWork, ref Info); LWork = Convert.ToInt32(Work[0]); if (LWork > 0) { Work = new double[LWork]; _dsyev.Run("N", "U", A.RowCount, ref EigenVectsData, 0, A.RowCount, ref EigenValsData, 0, ref Work, 0, LWork, ref Info); } else { //Error } #region Error /// = 0: successful exit /// .LT. 0: if INFO = -i, the i-th argument had an illegal value /// .GT. 0: if INFO = i, the algorithm failed to converge; i /// off-diagonal elements of an intermediate tridiagonal /// form did not converge to zero. if (Info < 0) { string infoSTg = Math.Abs(Info).ToString(); throw new ArgumentException("the " + infoSTg + " -th argument had an illegal value"); } else if (Info > 0) { string infoSTg = Math.Abs(Info).ToString(); throw new Exception("The algorithm failed to converge."); } #endregion return(EigenVals); }
/// <summary> /// See http://www.dotnumerics.com/NumericalLibraries/LinearAlgebra/CSharpCodeFiles/dsyev.aspx /// </summary> public void Dsyev(string jobz, string uplo, int n, ref double[] a, int offsetA, int ldA, ref double[] w, int offsetW, ref double[] work, int offsetWork, int lWork, ref int info) => dsyev.Run(jobz, uplo, n, ref a, offsetA, ldA, ref w, offsetW, ref work, offsetWork, lWork, ref info);