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

Identity matrix

Tags: None
(comma "," separated)
xissburg
Registered Member
Posts
5
Karma
0
OS

Identity matrix

Wed Jul 20, 2011 3:49 am
How create an identity matrix of size N? I found the DiagonalMatrix class and though it would be useful after calling the setIdentity method but later I just can't multiply it by a scalar and add to a SparseMatrix. What else can I use to achieve this effect?

Thanks.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Identity matrix

Wed Jul 20, 2011 8:42 am
to add a constant to the diagonal of a sparse matrix have a look at this thread:

viewtopic.php?f=74&t=95552
xissburg
Registered Member
Posts
5
Karma
0
OS

Re: Identity matrix

Thu Jul 21, 2011 3:26 am
That code adds the value to the first column of the matrix, or something. I am using a SparseMatrix, not a triangular one.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Identity matrix

Thu Jul 21, 2011 8:59 am
Then increment the iterator until it.index()==j and add the value. Of course this assume the diagonal entries already exists.
xissburg
Registered Member
Posts
5
Karma
0
OS

Re: Identity matrix

Sat Jul 23, 2011 4:51 pm
I did this instead

Code: Select all
Eigen::SparseMatrix<btScalar,Eigen::RowMajor> A(kSize, kSize);
   
for (int j=0; j<A.outerSize(); ++j) {
    A.insert(j,j) = timeStep*beta + 1;
}


Thanks for the help.


Bookmarks



Who is online

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