aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/snippets/RealQZ_compute.cpp
diff options
context:
space:
mode:
authorGravatar Alexey Korepanov <kaikaikai@yandex.ru>2012-07-28 08:24:44 -0500
committerGravatar Alexey Korepanov <kaikaikai@yandex.ru>2012-07-28 08:24:44 -0500
commitd937e67b48e23c5b4c4bf645a59abdcaef57b8b8 (patch)
tree4f995542962b276a16d11e7507aa6ab871b7a56d /doc/snippets/RealQZ_compute.cpp
parent52a0e0d65e4a638beabd54437846f9746ba87a50 (diff)
RealQZ: added example and some code comments
Diffstat (limited to 'doc/snippets/RealQZ_compute.cpp')
-rw-r--r--doc/snippets/RealQZ_compute.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/doc/snippets/RealQZ_compute.cpp b/doc/snippets/RealQZ_compute.cpp
new file mode 100644
index 000000000..a18da42e8
--- /dev/null
+++ b/doc/snippets/RealQZ_compute.cpp
@@ -0,0 +1,17 @@
+MatrixXf A = MatrixXf::Random(4,4);
+MatrixXf B = MatrixXf::Random(4,4);
+RealQZ<MatrixXf> qz(4); // preallocate space for 4x4 matrices
+qz.compute(A,B); // A = Q S Z, B = Q T Z
+
+// print original matrices and result of decomposition
+cout << "A:\n" << A << "\n" << "B:\n" << B << "\n";
+cout << "S:\n" << qz.matrixS() << "\n" << "T:\n" << qz.matrixT() << "\n";
+cout << "Q:\n" << qz.matrixQ() << "\n" << "Z:\n" << qz.matrixZ() << "\n";
+
+// verify precision
+cout << "\nErrors:"
+ << "\n|A-QSZ|: " << (A-qz.matrixQ()*qz.matrixS()*qz.matrixZ()).norm()
+ << ", |B-QTZ|: " << (B-qz.matrixQ()*qz.matrixT()*qz.matrixZ()).norm()
+ << "\n|QQ* - I|: " << (qz.matrixQ()*qz.matrixQ().adjoint() - MatrixXf::Identity(4,4)).norm()
+ << ", |ZZ* - I|: " << (qz.matrixZ()*qz.matrixZ().adjoint() - MatrixXf::Identity(4,4)).norm()
+ << "\n";