Calculating Determinants

I’m trying to fill a 4x4 matrix, and calculate its determinant, and the ROOT documentation isn’t particularly clear in how exactly to go about this.

here’s where I am so far (using arbitrary data):

double MatrixElements[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
TMatrix M(16,16);

after that I try to use the following to calculate det(M) (taken from the ROOT online documentation):

Double_t d1,d2;
TDecompLU lu(M);

I then get the error msg :
" Error in TDecompLU::DecomposeLUCrout:matrix is singular"

Am I filling the matrix incorrectly or calculating the determinant wrong…or both??

Thanks for any help


if you pass an array of 16 elements, you should create your matrix as

TMatrixD M(4,4);

then for calculating the determinant is sufficient you do

double det = M.Determinant(); 

Best Regards