xref: /aosp_15_r20/external/eigen/doc/examples/TutorialLinAlgComputeTwice.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li #include <iostream>
2*bf2c3715SXin Li #include <Eigen/Dense>
3*bf2c3715SXin Li 
4*bf2c3715SXin Li using namespace std;
5*bf2c3715SXin Li using namespace Eigen;
6*bf2c3715SXin Li 
main()7*bf2c3715SXin Li int main()
8*bf2c3715SXin Li {
9*bf2c3715SXin Li    Matrix2f A, b;
10*bf2c3715SXin Li    LLT<Matrix2f> llt;
11*bf2c3715SXin Li    A << 2, -1, -1, 3;
12*bf2c3715SXin Li    b << 1, 2, 3, 1;
13*bf2c3715SXin Li    cout << "Here is the matrix A:\n" << A << endl;
14*bf2c3715SXin Li    cout << "Here is the right hand side b:\n" << b << endl;
15*bf2c3715SXin Li    cout << "Computing LLT decomposition..." << endl;
16*bf2c3715SXin Li    llt.compute(A);
17*bf2c3715SXin Li    cout << "The solution is:\n" << llt.solve(b) << endl;
18*bf2c3715SXin Li    A(1,1)++;
19*bf2c3715SXin Li    cout << "The matrix A is now:\n" << A << endl;
20*bf2c3715SXin Li    cout << "Computing LLT decomposition..." << endl;
21*bf2c3715SXin Li    llt.compute(A);
22*bf2c3715SXin Li    cout << "The solution is now:\n" << llt.solve(b) << endl;
23*bf2c3715SXin Li }
24