2

Having two vectors:

Eigen::VectorXd A;
A  << 1, 2, 3, 4;
Eigen::VectorXd B;
B  << 1, 2, 3;

How to create following matrix C from vectors A and B? Matrix columns are equal to vector A, the elements of vector B are matrix column factors.

Eigen::MatrixXd C;
C  << 1, 2, 3,
      2, 4, 6,
      3, 6, 9,
      4, 8, 12;

1 Answers1

1

Vectors in Eigen are column vectors hence you could write something like this:

Eigen::Vector4d A;
Eigen::Vector3d B;
A << 1, 2, 3, 4;
B << 1, 2, 3;
const Eigen::MatrixXd C = A * B.transpose();

Note that in the memory the data is ordered in column major fashion. I mention this as it cought me by suprise the first time when I was debugging Eigen matrices.