} // private constructor for singleton pattern /// <summary> /// See http://www.dotnumerics.com/NumericalLibraries/LinearAlgebra/CSharpCodeFiles/dgeev.aspx /// </summary> public void Dgeev(string jobVl, string jobVr, int n, ref double[] a, int offsetA, int ldA, ref double[] wr, int offsetWr, ref double[] wi, int offsetWi, ref double[] vl, int offsetVl, int ldVl, ref double[] vr, int offsetVr, int ldVr, ref double[] work, int offsetWork, int lWork, ref int info) { dgeev.Run(jobVl, jobVr, n, ref a, offsetA, ldA, ref wr, offsetWr, ref wi, offsetWi, ref vl, offsetVl, ldVl, ref vr, offsetVr, ldVr, ref work, offsetWork, lWork, ref info); }
/// <summary> /// Computes the eigenvalues for an N-by-N real nonsymmetric matrix A. /// </summary> /// <param name="A">N-by-N real nonsymmetric matrix A.</param> /// <returns>The eigenvalues.</returns> public ComplexMatrix GetEigenvalues(Matrix A) { if (this._dgeev == null) { this._dgeev = new DGEEV(); } this.CheckDimensions(A); Matrix ACopy = A.Clone(); double[] ACopyData = ACopy.Data; Matrix RealEVectors = new Matrix(1, 1); double[] EigenVectsData = RealEVectors.Data; ComplexMatrix EigenVals = new ComplexMatrix(A.RowCount, 1); double[] REigVal = new double[A.RowCount]; double[] IEigVal = new double[A.RowCount]; //double[] EigenValsData = EigenVals.Data; int Info = 0; double[] VL = new double[A.RowCount]; double[] Work = new double[1]; int LWork = -1; //Calculamos LWORK _dgeev.Run("N", "N", A.RowCount, ref ACopyData, 0, ACopy.RowCount, ref REigVal, 0, ref IEigVal, 0, ref VL, 0, 1, ref EigenVectsData, 0, A.RowCount, ref Work, 0, LWork, ref Info); LWork = Convert.ToInt32(Work[0]); if (LWork > 0) { Work = new double[LWork]; _dgeev.Run("N", "N", A.RowCount, ref ACopyData, 0, ACopy.RowCount, ref REigVal, 0, ref IEigVal, 0, ref VL, 0, 1, ref EigenVectsData, 0, A.RowCount, 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 QR algorithm failed to compute all the // eigenvalues, and no eigenvectors have been computed; // elements i+1:N of WR and WI contain eigenvalues which // have converged. 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 QR algorithm failed to compute all the eigenvalues."); } #endregion for (int i = 0; i < EigenVals.RowCount; i++) { EigenVals[i, 0] = new Complex(REigVal[i], IEigVal[i]); } return(EigenVals); }