1
votes

I am trying to solve a simple least square of type Ax = b. The c++ eigen library offers several functionalities regarding this and I have seen some kind of solutions here: Solving system Ax=b in linear least squares fashion with complex elements and lower-triangular square A matrix and here: Least Squares Solution of Linear Algerbraic Equation Ax = By in Eigen C++ What I want to do is that using dynamic version of the matrix A and b. The elements of matrix A are floating points in my case and has 3 columns, but the number of data items (i.e. rows) will be dynamic (inside a loop). It will be helpful to have a short code snippet of basic declaration of A, b and filling out values.

1

1 Answers

1
votes

If you need dynamic matrices/vectors, just use:

MatrixXd m1(5,7); // double
VectorXd v1(23);  // double

MatrixXf m2(3,5); // floating
VectorXf v2(12);  // floating

Those variables will all be saved in heap.

If you need square matrices or vectors with fixed size (but be careful, they aren't dynamic!) use the following syntax:

Matrix3d m3; // double, size 3x3
Vector3d v3; // double, size 1x3

Matrix4d m4; // double, size 4x4
Vector4d v4; // double, size 1x4