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:
#include <iostream>
#include <vector>
#include "Eigen/Dense"
usingnamespace std;
usingnamespace 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;
}
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!