This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Diagonal matrix operations?

Tags: None
(comma "," separated)
snowshoe
Registered Member
Posts
4
Karma
0

Diagonal matrix operations?

Sun Aug 14, 2011 3:59 am
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?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Diagonal matrix operations?

Tue Aug 16, 2011 7:47 pm
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);


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]