xref: /aosp_15_r20/external/eigen/doc/snippets/HouseholderSequence_HouseholderSequence.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li Matrix3d v = Matrix3d::Random();
2*bf2c3715SXin Li cout << "The matrix v is:" << endl;
3*bf2c3715SXin Li cout << v << endl;
4*bf2c3715SXin Li 
5*bf2c3715SXin Li Vector3d v0(1, v(1,0), v(2,0));
6*bf2c3715SXin Li cout << "The first Householder vector is: v_0 = " << v0.transpose() << endl;
7*bf2c3715SXin Li Vector3d v1(0, 1, v(2,1));
8*bf2c3715SXin Li cout << "The second Householder vector is: v_1 = " << v1.transpose()  << endl;
9*bf2c3715SXin Li Vector3d v2(0, 0, 1);
10*bf2c3715SXin Li cout << "The third Householder vector is: v_2 = " << v2.transpose() << endl;
11*bf2c3715SXin Li 
12*bf2c3715SXin Li Vector3d h = Vector3d::Random();
13*bf2c3715SXin Li cout << "The Householder coefficients are: h = " << h.transpose() << endl;
14*bf2c3715SXin Li 
15*bf2c3715SXin Li Matrix3d H0 = Matrix3d::Identity() - h(0) * v0 * v0.adjoint();
16*bf2c3715SXin Li cout << "The first Householder reflection is represented by H_0 = " << endl;
17*bf2c3715SXin Li cout << H0 << endl;
18*bf2c3715SXin Li Matrix3d H1 = Matrix3d::Identity() - h(1) * v1 * v1.adjoint();
19*bf2c3715SXin Li cout << "The second Householder reflection is represented by H_1 = " << endl;
20*bf2c3715SXin Li cout << H1 << endl;
21*bf2c3715SXin Li Matrix3d H2 = Matrix3d::Identity() - h(2) * v2 * v2.adjoint();
22*bf2c3715SXin Li cout << "The third Householder reflection is represented by H_2 = " << endl;
23*bf2c3715SXin Li cout << H2 << endl;
24*bf2c3715SXin Li cout << "Their product is H_0 H_1 H_2 = " << endl;
25*bf2c3715SXin Li cout << H0 * H1 * H2 << endl;
26*bf2c3715SXin Li 
27*bf2c3715SXin Li HouseholderSequence<Matrix3d, Vector3d> hhSeq(v, h);
28*bf2c3715SXin Li Matrix3d hhSeqAsMatrix(hhSeq);
29*bf2c3715SXin Li cout << "If we construct a HouseholderSequence from v and h" << endl;
30*bf2c3715SXin Li cout << "and convert it to a matrix, we get:" << endl;
31*bf2c3715SXin Li cout << hhSeqAsMatrix << endl;
32