Spectral Integral Suite in C++
testLyap.cpp
Go to the documentation of this file.
1 
2 #include <fstream> // To output data to files
3 #include <iostream>
4 #include <stdio.h>
5 #include <sis.hpp>
6 #include <eigen3/unsupported/Eigen/MatrixFunctions>
7 using namespace std;
8 #ifndef CD_T
9 typedef complex<double> Cd_t;
10 #endif
11 //#define DEBUG
12 
13 #include <lyap.h>
14 #include <intWts.h>
15 
16 int main()
17 {
18  int size = 4;
19  Eigen::MatrixXcd AA(size, size), BB(size, size), QQ(size, size);
20  AA = Eigen::MatrixXcd::Random(size, size);
21  BB = Eigen::MatrixXcd::Random(size, size);
22  QQ = Eigen::MatrixXcd::Random(size, size);
23  Eigen::MatrixXcd X1 = dlyap(AA, BB, QQ);
24  // Check norm:
25  cout << "Testing dlyap: " << (AA * X1 * BB - X1 + QQ).norm() << endl;
26 
27  Eigen::MatrixXcd X2 = lyap(AA, BB, QQ);
28  // Check norm:
29  cout << "Testing lyap: " << (AA * X2 + X2 * BB + QQ).norm() << endl;
30  //Testing OrdQz:
31 
32  OrdQz qz(AA, BB);
33 
34 
35  cout << "qz info : " << qz.info << endl;
36  cout << "Test qz 1: " << (qz.VSL * qz.S * qz.VSR.adjoint() - AA).norm() << endl;
37  cout << "Test qz 2: " << (qz.VSL * qz.T * qz.VSR.adjoint() - BB).norm() << endl;
38 
39  // Test intWts:
40  sis::N = 91;
42  sis::ChebfunMat<Cd_t> f(1,1);
43  f << 1.0 - sis::y*sis::y;
44 
45  f.p2c();
46 
47  Eigen::MatrixXcd fm(sis::N+1,1);
48  for (int i = 0 ;i < sis::N+1; i++){
49  fm(i,0) = f(0,0).v[i];
50  }
51 
52  Eigen::MatrixXd Iw = intWts(sis::N);
53  cout << "Testing intWts: " << fm.adjoint() * Iw * fm << ", Actual value: " << 16.0/15.0 <<endl;
54 
55  // Testing square roots module.
56  Eigen::MatrixXd sqrtIw = Iw.sqrt();
57  cout << "Testing matrix square root, norm: " << (sqrtIw*sqrtIw - Iw).norm() << endl;
58  return 0;
59 }
void sis_setup()
Definition: sis.hpp:954
int main()
Definition: testLyap.cpp:16
complex< double > Cd_t
Definition: testLyap.cpp:9
Eigen::MatrixXcd lyap(Eigen::MatrixXcd A, Eigen::MatrixXcd B, Eigen::MatrixXcd Q)
Solves the Lyapunov/ sylvester equation: AX + XB + Q = 0.
Definition: lyap.h:133
Definition: lyap.h:34
Definition: sis.hpp:260
Eigen::MatrixXcd S
Definition: lyap.h:36
std::complex< T > size(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &in)
This function is useful to see size of Eigen matrices. Returns a complex number, where the real part ...
Definition: sis.hpp:901
int info
Definition: lyap.h:37
Eigen::MatrixXcd VSR
Definition: lyap.h:36
Eigen::MatrixXcd T
Definition: lyap.h:36
Eigen::MatrixXd intWts(int N)
Definition: intWts.h:2
Eigen::MatrixXcd VSL
Definition: lyap.h:36
int N
Specifies number of Chebyshev polynomials, default N = 31.
Definition: sis.hpp:472
void p2c()
Converts every element to Cheb-space, if not already in Cheb-space.
Definition: sis.hpp:2093
Eigen::MatrixXcd dlyap(Eigen::MatrixXcd A, Eigen::MatrixXcd B, Eigen::MatrixXcd Q)
Solves the Lyapunov/ sylvester equation: AXB - X + Q = 0.
Definition: lyap.h:217
std::valarray< SIS_TYPE > y(N+1)
This class holds a matrix of Chebfuns.
Definition: sis.hpp:2004