1MatrixXd X = MatrixXd::Random(5,5);
2MatrixXd A = X + X.transpose();
3cout << "Here is a random symmetric matrix, A:" << endl << A << endl;
4X = MatrixXd::Random(5,5);
5MatrixXd B = X * X.transpose();
6cout << "and a random postive-definite matrix, B:" << endl << B << endl << endl;
7
8GeneralizedSelfAdjointEigenSolver<MatrixXd> es(A,B);
9cout << "The eigenvalues of the pencil (A,B) are:" << endl << es.eigenvalues() << endl;
10cout << "The matrix of eigenvectors, V, is:" << endl << es.eigenvectors() << endl << endl;
11
12double lambda = es.eigenvalues()[0];
13cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
14VectorXd v = es.eigenvectors().col(0);
15cout << "If v is the corresponding eigenvector, then A * v = " << endl << A * v << endl;
16cout << "... and lambda * B * v = " << endl << lambda * B * v << endl << endl;
17