-1

I need to create a diagonal MatrixXd in C++ using Eigen library in which the elements on the diagonal are N replication of a shorter VectorXd.

VectorXd R; // a vector of size n

VectorXd V; // a vector of size n*N corresponding to N concatenated replicate of R, i don't khow how to create

MatrixXd D=MatrixXd(V.asDiagonal()); //my diagonal matrix on size nN x nN

thanks.

user58058
  • 3
  • 3

1 Answers1

0

something along the lines of

VectorXd V(N * R.innerSize()); // construct vector of size N * n
for(size_t i = 0; i < n; ++i)
    for(size_t j = 0; j < R.innerSize(); ++j)
        V[i * R.innerSize() + j] = R[j];
BeyelerStudios
  • 4,243
  • 19
  • 38