3 typedef complex<double>
Cd_t;
7 void zgees_(
char *JOBVS,
char *SORT,
bool (*SELCTG)(
Cd_t a),
int *
N,
Cd_t *A,
int *LDA,
int *SDIM,
Cd_t *W,
Cd_t *VS,
int *LDVS,
Cd_t *WORK,
int *LWORK,
double *RWORK,
bool *BWORK,
int *INFO);
12 void ztgsen_(
int* IJOB,
bool* WANTQ,
bool* WANTZ,
bool* SELECT,
int*
N,
Cd_t* A,
int* LDA,
Cd_t* B,
int* LDB,
Cd_t* ALPHA,
Cd_t* BETA,
Cd_t* Q,
int* LDQ,
Cd_t* Z,
int* LDZ,
int* M,
double* PL,
double* PR,
double* DIF,
Cd_t* WORK,
int* LWORK,
int* IWORK,
int* LIWORK,
int* INFO);
18 if (abs(alpha / beta) > 1e10 || (abs(beta) == 0.0) ) {
29 void zgges_(
char *JOBVSL,
char *JOBVSR,
char *SORT,
bool (*SELCTG)(
Cd_t a,
Cd_t b),
int *
N,
Cd_t *A,
int *LDA,
Cd_t *B,
int *LDB,
31 int *LWORK,
double *RWORK,
bool *BWORK,
int *INFO);
40 OrdQz(Eigen::MatrixXcd A, Eigen::MatrixXcd B)
45 void compute(Eigen::MatrixXcd A, Eigen::MatrixXcd B){
48 std::complex<double> wkopt;
55 T.resize(r, r);
T = B;
61 int ldac = A.outerStride();
62 int ldbc = B.outerStride();
65 int ldvl =
VSL.outerStride();
66 int ldvr =
VSR.outerStride();
77 zgges_(&jobvl, &jobvr, &sort, &
criteria_, &
N,
S.data(), &ldac,
T.data(), &ldbc, &sdim,
alpha.data(),
beta.data(),
VSL.data(), &ldvl,
VSR.data(), &ldvr, &workc[0], &lwork, &rwork[0], bwork, &
info);
80 lwork = int(
real(workc[0]));
83 zgges_(&jobvl, &jobvr, &sort, &
criteria_, &
N,
S.data(), &ldac,
T.data(), &ldbc, &sdim,
alpha.data(),
beta.data(),
VSL.data(), &ldvl,
VSR.data(), &ldvr, &workc[0], &lwork, &rwork[0], bwork, &
info);
90 for (
int i = 0; i <
alpha.size(); i++) {
92 cout << select[i] << endl;
96 Eigen::MatrixXcd S1 =
S, T1 =
T;
105 ztgsen_(&ijob, &wantq, &wantz, select, &
N,
S.data(), &ldac,
T.data(), &ldbc,
alpha.data(),
beta.data(),
VSL.data(), &ldvl,
VSR.data(), &ldvr, &
M, &pl, &pr, &dif, &workc[0], &lwork, &iwork[0], &liwork, &
info);
106 lwork = int(
real(workc[0]));
109 iwork.resize(liwork);
110 ztgsen_(&ijob, &wantq, &wantz, select, &
N,
S.data(), &ldac,
T.data(), &ldbc,
alpha.data(),
beta.data(),
VSL.data(), &ldvl,
VSR.data(), &ldvr, &
M, &pl, &pr, &dif, &workc[0], &lwork, &iwork[0], &liwork, &
info);
111 cout <<
"info : " <<
info << endl;
113 cout <<
"M : " <<
M << endl;
133 Eigen::MatrixXcd
lyap(Eigen::MatrixXcd A, Eigen::MatrixXcd B, Eigen::MatrixXcd Q) {
134 Eigen::MatrixXcd X, X1;
135 X1.setConstant(
Cd_t(0.0,0.0));
138 Eigen::MatrixXcd T, Aad;
140 Aad.adjointInPlace();
143 cout <<
"A: " << A << endl;
144 cout <<
"Aad: " << Aad << endl;
152 int lda = Aad.outerStride();
156 Eigen::MatrixXcd W(
N,1), Vs(
N,
N);
164 zgees_(&jobvs, &sort, &
forZgees, &
N, T.data(), &lda, &sdim, W.data(), Vs.data(), &ldvs, &workc[0], &lwork, &rwork[0], bwork, &info);
165 lwork = int(
real(workc[0]));
167 zgees_(&jobvs, &sort, &
forZgees, &
N, T.data(), &lda, &sdim, W.data(), Vs.data(), &ldvs, &workc[0], &lwork, &rwork[0], bwork, &info);
171 cout <<
"Error in norm: " << (Aad - Vs*T*Vs.adjoint()).norm() << endl;
172 cout <<
"Error in norm: " << (A - Vs * T.adjoint() * Vs.adjoint()).norm() << endl;
175 Eigen::MatrixXcd Tad = T.adjoint(), T2 = B, Us(
N,
N);
179 zgees_(&jobvs, &sort, &
forZgees, &
N, T2.data(), &lda, &sdim, W.data(), Us.data(), &ldvs, &workc[0], &lwork, &rwork[0], bwork, &info);
181 cout <<
"Error in norm: " << (B - Us * T2 * Us.adjoint()).norm() << endl;
189 Eigen::MatrixXcd Q1 = Vs.adjoint() * Q * Us;
193 for (
int k = 0; k < p; k++) {
194 for (
int l = 0; l < q; l++) {
196 for (
int j = 0; j < k ; j++) {
197 sum1 += (Tad(k, j) * X1(j, l));
199 for (
int i = 0; i < l ; i++) {
200 sum2 += (X1(k, i) * T2(i, l));
202 X1(k, l) = (-Q1(k, l) - sum1 - sum2) / (Tad(k, k) + T2(l, l));
205 X = Vs*X1*Us.adjoint();
208 cout <<
"Error in norm: " << (Tad*X1 + X1*T2 + Q1).norm() << endl;
209 cout <<
"Error: " << (Tad * X1 + X1 * T2 + Q1) << endl;
210 cout <<
"Error in norm: " << (A * X + X * B + Q).norm() << endl;
211 cout <<
"Error: " << (A * X + X * B + Q) << endl;
217 Eigen::MatrixXcd
dlyap(Eigen::MatrixXcd A, Eigen::MatrixXcd B, Eigen::MatrixXcd Q)
219 Eigen::MatrixXcd X, X1;
220 X1.setConstant(
Cd_t(0.0, 0.0));
223 Eigen::MatrixXcd T, Aad;
225 Aad.adjointInPlace();
236 int lda = Aad.outerStride();
240 Eigen::MatrixXcd W(
N, 1), Vs(
N,
N);
248 zgees_(&jobvs, &sort, &
forZgees, &
N, T.data(), &lda, &sdim, W.data(), Vs.data(), &ldvs, &workc[0], &lwork, &rwork[0], bwork, &info);
249 lwork = int(
real(workc[0]));
251 zgees_(&jobvs, &sort, &
forZgees, &
N, T.data(), &lda, &sdim, W.data(), Vs.data(), &ldvs, &workc[0], &lwork, &rwork[0], bwork, &info);
255 cout <<
"Error in norm: " << (Aad - Vs * T * Vs.adjoint()).norm() << endl;
256 cout <<
"Error in norm: " << (A - Vs * T.adjoint() * Vs.adjoint()).norm() << endl;
259 Eigen::MatrixXcd Tad = T.adjoint(), T2 = B, Us(
N,
N);
262 zgees_(&jobvs, &sort, &
forZgees, &
N, T2.data(), &lda, &sdim, W.data(), Us.data(), &ldvs, &workc[0], &lwork, &rwork[0], bwork, &info);
264 cout <<
"Error in norm: " << (B - Us * T2 * Us.adjoint()).norm() << endl;
272 Eigen::MatrixXcd Q1 = Vs.adjoint() * Q * Us;
276 for (
int k = 0; k < p; k++) {
277 for (
int l = 0; l < q; l++) {
279 for (
int j = 0; j < k+1; j++) {
280 for (
int i = 0; i < l+1; i++) {
281 sum1 += (Tad(k, j) * X1(j, i) * T2(i,l));
288 X1(k, l) = (-Q1(k, l) - sum1) / (Tad(k, k) * T2(l, l) -
Cd_t(1.0,0.0));
291 X = Vs * X1 * Us.adjoint();
294 cout <<
"Error in norm: " << (Tad * X1* T2 - X1 + Q1).norm() << endl;
295 cout <<
"Error: " << (Tad * X1 * T2 - X1 + Q1) << endl;
296 cout <<
"Error in norm: " << (A * X * B - X + Q).norm() << endl;
297 cout <<
"Error: " << (A * X * B - X + Q) << endl;
Eigen::MatrixXcd lyap(Eigen::MatrixXcd A, Eigen::MatrixXcd B, Eigen::MatrixXcd Q)
Solves the Lyapunov/ sylvester equation: AX + XB + Q = 0.
bool criteria_(Cd_t alpha, Cd_t beta)
void ztgsen_(int *IJOB, bool *WANTQ, bool *WANTZ, bool *SELECT, int *N, Cd_t *A, int *LDA, Cd_t *B, int *LDB, Cd_t *ALPHA, Cd_t *BETA, Cd_t *Q, int *LDQ, Cd_t *Z, int *LDZ, int *M, double *PL, double *PR, double *DIF, Cd_t *WORK, int *LWORK, int *IWORK, int *LIWORK, int *INFO)
void zgges_(char *JOBVSL, char *JOBVSR, char *SORT, bool(*SELCTG)(Cd_t a, Cd_t b), int *N, Cd_t *A, int *LDA, Cd_t *B, int *LDB, int *SDIM, Cd_t *ALPHA, Cd_t *BETA, Cd_t *VSL, int *LDVSL, Cd_t *VSR, int *LDVSR, Cd_t *WORK, int *LWORK, double *RWORK, bool *BWORK, int *INFO)
void zgees_(char *JOBVS, char *SORT, bool(*SELCTG)(Cd_t a), int *N, Cd_t *A, int *LDA, int *SDIM, Cd_t *W, Cd_t *VS, int *LDVS, Cd_t *WORK, int *LWORK, double *RWORK, bool *BWORK, int *INFO)
int N
Specifies number of Chebyshev polynomials, default N = 31.
Eigen::MatrixXcd dlyap(Eigen::MatrixXcd A, Eigen::MatrixXcd B, Eigen::MatrixXcd Q)
Solves the Lyapunov/ sylvester equation: AXB - X + Q = 0.
valarray< T > real(const valarray< complex< T > > &in)
real part of a complex valarray
void compute(Eigen::MatrixXcd A, Eigen::MatrixXcd B)
OrdQz(Eigen::MatrixXcd A, Eigen::MatrixXcd B)