Reply to topic

Assigning a sparse matrix in Eigen

marvisiyer
Registered Member
Posts
19
Karma
0

Assigning a sparse matrix in Eigen

Wed Sep 26, 2012 11:37 pm
How to assign a sparse matrix in Eigen?
Code: Select all
int n = 10000;
VectorXd x(n), b(n);
SparseMatrix<double> A(n,n);

How to assign individual elements of A?
Thanks
User avatar ggael
Moderator
Posts
2204
Karma
15
OS
marvisiyer
Registered Member
Posts
19
Karma
0


Unfortunately, I do not understand what it does. Can you give me an example? For instance, how should I assign the following 10 by 8 sparse matrix?

A(1,2) = 3; A(1,4) = 10;
A(2,1) = 9; A(2,8) = 9;
A(4,7) = 11;
A(7,4) = 21;
A(9,3) = 45;
A(10,7) = 76;
zoharl
Registered Member
Posts
50
Karma
0
OS
You can simply use:

Code: Select all
A.coeffRef(1,2) = 3;
A.coeffRef(1,4) = 10;
...
A.finalize();


But it would be slow, or you can create a a sparse matrix from triplets, such as the example after the "Here is a typical usage example: " in ggael's link.

 
Reply to topic

Bookmarks



Who is online

Registered users: alake, Alexa [Bot], Baidu [Spider], Bing [Bot], bshah, Exabot [Bot], Google [Bot], grubaugh, Hans, Naver Yeti [Spider], onesandzeros, orbmiser, pedrorodriguez, pvonz, searchfgold6789, Uri_Herrera, Yahoo [Bot]