34 #ifndef __H__UG__EIGENVALUE__
35 #define __H__UG__EIGENVALUE__
37 #ifdef LAPACK_AVAILABLE
40 #include "../small_algebra.h"
46 #include "../small_matrix/densematrix.h"
68 template<
typename A_type,
typename TLambdaVectorType>
70 TLambdaVectorType &lambda, DenseMatrix<A_type> &B,
bool bSortEigenvalues=
false)
72 size_t N = A.num_rows();
75 std::vector<double> alphar; alphar.resize(N);
76 std::vector<double> alphai; alphai.resize(N);
77 std::vector<double> beta; beta.resize(N);
86 info = gegv(
true,
false, N, &A(0,0), N, &B(0,0), N, &alphar[0], &alphai[0], &beta[0], &X(0,0), N, NULL, 0, &dWorksize, worksize);
88 info = gegv(
false,
true, N, &A(0,0), N, &B(0,0), N, &alphar[0], &alphai[0], &beta[0], NULL, N, &X(0,0), N, &dWorksize, worksize);
91 worksize = (int)dWorksize;
92 double *dwork =
new double[worksize];
94 info = gegv(
true,
false, N, &A(0,0), N, &B(0,0), N, &alphar[0], &alphai[0], &beta[0], &X(0,0), N, NULL, 0, dwork, worksize);
96 info = gegv(
false,
true, N, &A(0,0), N, &B(0,0), N, &alphar[0], &alphai[0], &beta[0], NULL, N, &X(0,0), N, dwork, worksize);
101 for(
size_t i=0; i<N; i++)
102 lambda[i] = std::complex<double>(alphar[i]/beta[i], alphai[i]/beta[i]);
108 for(
int i=N-1; i>0; i--)
110 for(
int j=0; j<i; j++)
111 if(std::abs(lambda[j]) > std::abs(lambda[j+1]))
113 std::swap(lambda[j], lambda[j+1]);
114 for(
size_t r = 0; r<X.num_rows(); r++)
115 std::swap(X(r, j), X(r, j+1));
127 template<
typename A_type,
typename TLambdaVectorType>
131 UG_ASSERT(0,
"GeneralizedEigenvalueProblemComplex is only implemented for LAPACK at the moment");
Definition: densematrix.h:57
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define THROW_IF_NOT_EQUAL_4(s1, s2, s3, s4)
Definition: error.h:183
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
@ ColMajor
Definition: storage.h:49
@ RowMajor
Definition: storage.h:48
int GeneralizedEigenvalueProblemComplex(DenseMatrix< A_type > &A, DenseMatrix< A_type > &X, TLambdaVectorType &lambda, DenseMatrix< A_type > &B, bool bSortEigenvalues=false)
Definition: eigenvalue2.h:128