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

Assigning a sparse matrix in Eigen

Tags: None
(comma "," separated)
marvisiyer
Registered Member
Posts
21
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
3447
Karma
19
OS
marvisiyer
Registered Member
Posts
21
Karma
0
ggael wrote:it's explained there: http://eigen.tuxfamily.org/dox-devel/Tu ... rseFilling


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
55
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.


Bookmarks



Who is online

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