Registered Member
|
It seems that no operation is defined for multiplying a DiagonalMatrix by a scalar, nor is it possible to add a DiagonalMatrix to a SparseMatrix. Is this true? Also, is it possible to define a diagonal matrix containing a single constant scalar value? I see that one can accomplish the same thing by defining a vector v and applying v.setConstant(scalar), but adding v.asDiagonal() to a sparse matrix doesn't work. Any suggestions, anyone?
|
Moderator
|
hm you are right on all points. Regarding scalar multiplication this is very easy to do and in the mean time you can do (D.diagonal()*scalar).asDiagonal() without overhead (expect the writing )
To make a constant diagonal matrix you can do: VectorXd::Constant(v,size).asDiagonal() To add a diagonal matrix to an existing sparse matrix you can currently do: VectorXd diag(size); diag = ...; for(int j=0; j<size;++j) M.coeffRef(j,j) += diag(j); |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]