Solving Ax = b with Eigen library in c++

by Dhruvin Naik   Last Updated May 15, 2019 16:26 PM

I am trying to Solve Ax = b using least square method. I am using Eigen library to solve this. The input to my function are Matrix A (vector>) and RhS vector b. I need to convert these to Eigen::MatrixXd and Eigen::VectorXd. I could convert b easily to Eigen::VectorXd. But I am not able to form the Eigen::MatrixXd.

Thanks for your answer in advance.

Eigen::MatrixXd A_eig(A.size(), A.at(0).size());

for (int i = 0; i < A.size(); ++i)
    for (int j = 0; j < A.at(0).size(); ++j)
        A_eig(i,j) = A.at(i).at(j);

Eigen::MatrixXd A_eig(A.size(), A.at(0).size());

for (int i = 0; i < A.size(); ++i)
    for (int j = 0; j < A.at(0).size(); ++j)
        A_eig(i,j) = A.at(i).at(j);
Tags : c++ vector std eigen


Related Questions


Updated April 06, 2017 11:26 AM

Updated July 02, 2017 17:26 PM

Updated April 16, 2017 09:26 AM

Updated September 09, 2017 12:26 PM

Updated April 25, 2018 06:26 AM