Solving linear equations with TDecompSparse

I want to solve a large set of linear equations using linear algebra, i.e., get x in Ax = b equation.
For small sets this procedure works well:

//N - size of the NxN matrix A
//NN - number of non-zero elements in matrix A
//I,J, V - arrays of matrix indices and values (non-zero elements only)
TMatrixD A(N,N);
for(Int_t i = 0; i<NN;i++){
A(I[i],J[i]) = V[i];

TDecompSVD de(A,0);

And the b-vector contains the correct result.
For large sets of equations I want to use a sparse matrix:

TMatrixDSparse A(N,N);
for(Int_t i = 0; i<NN;i++){
A(I[i],J[i]) = V[i];

TDecompSparse de(A,0);

But the results is a complete nonsense, even for small equation sets. What do I do wrong? Thanks!

Tested with ROOT 5 and 6, on Windows and MacOS.

Hi Oldrich,

Thanks for the post. Let me add in the loop @mdessole and @moneta .


Hi Oldrich,

TDecompSVD can only be used for positive definite matrices.


1 Like

Hi Eddy,

yes, but I believe that the problem is in TDecompSparse. The TDecompSVD (or any other decomposition on dense matrix) works fine for my case. I also do not get any error/warning messages when using TDecompSparse, and I was unable to find much in the documentation. Is there any example code for using TDecompSparse? Thanks.

Hi @Oldrich_Novotny,

TDecompSparse solves a sparse linear system Ax=b where A is sparse and positive definite, i.e. A is symmetric and all its eigenvalues are positive real numbers. Does your matrix A fulfil this requirement?


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.