I am trying to initialize a matrix (using the Eigen library) to have a nonzero value when I create it. Is there a nice way to do this without a for loop?
For example, if I wanted to initialize the whole matrix to 1.0, I would like to do something like:
Eigen::MatrixXd mat(i,j) = 1.0;
or
Eigen::MatrixXd mat(i,j);
mat += 1.0;
(I am used to this type of thing in MATLAB, and it would make Eigen even nicer to use than it already is. I suspect there is a built-in method somewhere that does this, that I have not found.)
A sub-question to this question would be how to set a block of matrix elements to a set value, something ilke:
mat.block(i,j,k,l) = 1.0;
Eigen::MatrixXd::Ones(rows,cols)
, like:Eigen::MatrixXd mat(3,3) = 1.5 * Eigen::MatrixXd::Ones(3,3)
It's not quite like MATLAB, but close – ThennaEigen::Array
but not with linear algebra matrices because in this case a scalar value should rather be assimilated as the identity matrix times this scalar value. – Bradbradan