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 | Matrix3d v = Matrix3d::Random();
|
---|
11 | cout << "The matrix v is:" << endl;
|
---|
12 | cout << v << endl;
|
---|
13 |
|
---|
14 | Vector3d v0(1, v(1,0), v(2,0));
|
---|
15 | cout << "The first Householder vector is: v_0 = " << v0.transpose() << endl;
|
---|
16 | Vector3d v1(0, 1, v(2,1));
|
---|
17 | cout << "The second Householder vector is: v_1 = " << v1.transpose() << endl;
|
---|
18 | Vector3d v2(0, 0, 1);
|
---|
19 | cout << "The third Householder vector is: v_2 = " << v2.transpose() << endl;
|
---|
20 |
|
---|
21 | Vector3d h = Vector3d::Random();
|
---|
22 | cout << "The Householder coefficients are: h = " << h.transpose() << endl;
|
---|
23 |
|
---|
24 | Matrix3d H0 = Matrix3d::Identity() - h(0) * v0 * v0.adjoint();
|
---|
25 | cout << "The first Householder reflection is represented by H_0 = " << endl;
|
---|
26 | cout << H0 << endl;
|
---|
27 | Matrix3d H1 = Matrix3d::Identity() - h(1) * v1 * v1.adjoint();
|
---|
28 | cout << "The second Householder reflection is represented by H_1 = " << endl;
|
---|
29 | cout << H1 << endl;
|
---|
30 | Matrix3d H2 = Matrix3d::Identity() - h(2) * v2 * v2.adjoint();
|
---|
31 | cout << "The third Householder reflection is represented by H_2 = " << endl;
|
---|
32 | cout << H2 << endl;
|
---|
33 | cout << "Their product is H_0 H_1 H_2 = " << endl;
|
---|
34 | cout << H0 * H1 * H2 << endl;
|
---|
35 |
|
---|
36 | HouseholderSequence<Matrix3d, Vector3d> hhSeq(v, h);
|
---|
37 | Matrix3d hhSeqAsMatrix(hhSeq);
|
---|
38 | cout << "If we construct a HouseholderSequence from v and h" << endl;
|
---|
39 | cout << "and convert it to a matrix, we get:" << endl;
|
---|
40 | cout << hhSeqAsMatrix << endl;
|
---|
41 |
|
---|
42 | return 0;
|
---|
43 | }
|
---|