How to pass values of vectors to 2D matrix or a vector in Eigen

Hi all,
I am trying to solve a linear equation Ax=b using Eigen's abilities for the A as a square 2D vector. I have the A and b as C++ based 2D vector and 1D vector respectively. However, I could not find a way to pass the values of them to the Eigen format matrix and vectors. Would you please let me how to copy the variable in Eigen format?
Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <vector>

#include "Eigen/Dense"

using namespace std;
using namespace Eigen;
int main()
{
    // Let's consider that the A and b are following CPP based vectors:
    vector<vector<double>> mainA= { { 10.,11.,12. },{ 13.,14.,15. },{ 16.,17.,18. } };	
    vector<double> mainB = { 2.,5.,8. };

    // ??? Here I need to do something to pass the values to the following Eigen 
    //format matrix and vector

    Matrix3f A;
    Vector3f b;
	
    cout << "Here is the matrix A:\n" << A << endl;
    cout << "Here is the vector b:\n" << b << endl;
    Vector3f x = A.colPivHouseholderQr().solve(b);
    cout << "The solution is:\n" << x << endl;

}


Last edited on
https://eigen.tuxfamily.org/dox/group__TutorialMatrixClass.html has Coefficient Accessors
and
https://eigen.tuxfamily.org/dox/group__TutorialMapClass.html has Map

... assuming that is the "Eigen" that you are talking about.
I tried the Map class, but I was wondering what should I include in my class to be able to use the Map?! I checked the websites but could not find a robust answer!
Topic archived. No new replies allowed.