| MatrixXd X = MatrixXd::Random(5, 5); |
| MatrixXd A = X + X.transpose(); |
| cout << "Here is a random symmetric 5x5 matrix, A:" << endl << A << endl << endl; |
| |
| SelfAdjointEigenSolver<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; |
| |
| double lambda = es.eigenvalues()[0]; |
| cout << "Consider the first eigenvalue, lambda = " << lambda << endl; |
| VectorXd 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 * v << endl << endl; |
| |
| MatrixXd D = es.eigenvalues().asDiagonal(); |
| MatrixXd V = es.eigenvectors(); |
| cout << "Finally, V * D * V^(-1) = " << endl << V * D * V.inverse() << endl; |