| Line | |
|---|
| 1 | #include <Eigen/Dense>
|
|---|
| 2 | #include <iostream>
|
|---|
| 3 |
|
|---|
| 4 | using namespace Eigen;
|
|---|
| 5 | using namespace std;
|
|---|
| 6 |
|
|---|
| 7 | int main(int, char**)
|
|---|
| 8 | {
|
|---|
| 9 | cout.precision(3);
|
|---|
| 10 | MatrixXf A = MatrixXf::Random(4,4);
|
|---|
| 11 | MatrixXf B = MatrixXf::Random(4,4);
|
|---|
| 12 | RealQZ<MatrixXf> qz(4); // preallocate space for 4x4 matrices
|
|---|
| 13 | qz.compute(A,B); // A = Q S Z, B = Q T Z
|
|---|
| 14 |
|
|---|
| 15 | // print original matrices and result of decomposition
|
|---|
| 16 | cout << "A:\n" << A << "\n" << "B:\n" << B << "\n";
|
|---|
| 17 | cout << "S:\n" << qz.matrixS() << "\n" << "T:\n" << qz.matrixT() << "\n";
|
|---|
| 18 | cout << "Q:\n" << qz.matrixQ() << "\n" << "Z:\n" << qz.matrixZ() << "\n";
|
|---|
| 19 |
|
|---|
| 20 | // verify precision
|
|---|
| 21 | cout << "\nErrors:"
|
|---|
| 22 | << "\n|A-QSZ|: " << (A-qz.matrixQ()*qz.matrixS()*qz.matrixZ()).norm()
|
|---|
| 23 | << ", |B-QTZ|: " << (B-qz.matrixQ()*qz.matrixT()*qz.matrixZ()).norm()
|
|---|
| 24 | << "\n|QQ* - I|: " << (qz.matrixQ()*qz.matrixQ().adjoint() - MatrixXf::Identity(4,4)).norm()
|
|---|
| 25 | << ", |ZZ* - I|: " << (qz.matrixZ()*qz.matrixZ().adjoint() - MatrixXf::Identity(4,4)).norm()
|
|---|
| 26 | << "\n";
|
|---|
| 27 |
|
|---|
| 28 | return 0;
|
|---|
| 29 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.