aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/snippets/EigenSolver_EigenSolver_MatrixType.cpp
diff options
context:
space:
mode:
authorGravatar Jitse Niesen <jitse@maths.leeds.ac.uk>2010-03-31 11:59:11 +0100
committerGravatar Jitse Niesen <jitse@maths.leeds.ac.uk>2010-03-31 11:59:11 +0100
commit1b3f7f2feef34d0506e66e7514130a3994589be8 (patch)
treeedcd3881af84b59f23eb608f4aeb1a5ee97255ab /doc/snippets/EigenSolver_EigenSolver_MatrixType.cpp
parent338ec0390fc89d9f202d2eb2a41725b7fc738a0a (diff)
Extend documentation and add examples for EigenSolver class.
Diffstat (limited to 'doc/snippets/EigenSolver_EigenSolver_MatrixType.cpp')
-rw-r--r--doc/snippets/EigenSolver_EigenSolver_MatrixType.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/doc/snippets/EigenSolver_EigenSolver_MatrixType.cpp b/doc/snippets/EigenSolver_EigenSolver_MatrixType.cpp
new file mode 100644
index 000000000..c1d9fa879
--- /dev/null
+++ b/doc/snippets/EigenSolver_EigenSolver_MatrixType.cpp
@@ -0,0 +1,16 @@
+MatrixXd A = MatrixXd::Random(6,6);
+cout << "Here is a random 6x6 matrix, A:" << endl << A << endl << endl;
+
+EigenSolver<MatrixXd> es(A);
+cout << "The eigenvalues of A are:" << endl << es.eigenvalues() << endl;
+cout << "The matrix of eigenvectors, V, is:" << endl << es.eigenvectors() << endl << endl;
+
+complex<double> lambda = es.eigenvalues()[0];
+cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
+VectorXcd v = es.eigenvectors().col(0);
+cout << "If v is the corresponding eigenvector, then lambda * v = " << endl << lambda * v << endl;
+cout << "... and A * v = " << endl << A.cast<complex<double> >() * v << endl << endl;
+
+MatrixXcd D = es.eigenvalues().asDiagonal();
+MatrixXcd V = es.eigenvectors();
+cout << "Finally, V * D * V^(-1) = " << endl << V * D * V.inverse() << endl;