xref: /aosp_15_r20/external/eigen/doc/snippets/LLT_solve.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li typedef Matrix<float,Dynamic,2> DataMatrix;
2*bf2c3715SXin Li // let's generate some samples on the 3D plane of equation z = 2x+3y (with some noise)
3*bf2c3715SXin Li DataMatrix samples = DataMatrix::Random(12,2);
4*bf2c3715SXin Li VectorXf elevations = 2*samples.col(0) + 3*samples.col(1) + VectorXf::Random(12)*0.1;
5*bf2c3715SXin Li // and let's solve samples * [x y]^T = elevations in least square sense:
6*bf2c3715SXin Li Matrix<float,2,1> xy
7*bf2c3715SXin Li  = (samples.adjoint() * samples).llt().solve((samples.adjoint()*elevations));
8*bf2c3715SXin Li cout << xy << endl;
9