## Assigning a sparse matrix in Eigen

marvisiyer
Registered Member
Posts
20
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);`

Thanks
ggael
Moderator
Posts
2740
Karma
17
OS

### Re: Assigning a sparse matrix in Eigen

Thu Sep 27, 2012 6:07 am
marvisiyer
Registered Member
Posts
20
Karma
0

### Re: Assigning a sparse matrix in Eigen

Mon Feb 04, 2013 10:56 pm

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
51
Karma
0
OS

### Re: Assigning a sparse matrix in Eigen

Tue Feb 05, 2013 6:46 am
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.

## Who is online

Registered users: Armagetron, Baidu [Spider], Bing [Bot], davidemme, Exabot [Bot], Google [Bot], google01103, odysseus-art, rsupremo, Saabhero, slangkamp, Soukyuu, vicr123, Yahoo [Bot]