Question about TMatrixTSym

Dear friends of root,

I made a strange observation. If you create a TMatrixSym with:

TMatrixDSym A(2);
and then set
A(1,0) = 1;
one gets a matrix the is obviously not symmetric any more
root [8] A.Print();

2x2 matrix is as follows

 |      0    |      1    |

0 | 0 0
1 | 1 0

because setting an off diagonal element in a symmetric matrix will not automatically set the corresponding element, too.

yet if you call

A.IsSymmetric()
you get true because IsSymmetric() returns a hard coded true all the time!

If the use can the set a “TMatrixSym” matrix into an non symmetric state it seems wrong that always returns true.

Is this some kind of know bug? Or did I get anything wrong?
Thanks in advance for any kind on enlightenment.

kind regards

Moritz Nadler

Hi,
This is a known problem of TMatrixTSym which uses a full storage in memory (but not in the disk). This is different with respect to SMatrix, where only n(n+1)/2 elements are stored in memory.
You need to be careful when assigning off-diagonal elements to do for both M(i,j) and M(j,i)

Lorenzo

Hi,

The TMatrixTSym documentation states:

Actually all operations (multiplication, adding , inversion , etc.) use only the
upper right triangle.

the operator(i,j) and Print should/will be updated to reflect this behavior.

  • Eddy

[quote]Actually all operations (multiplication, adding , inversion , etc.) use only the
upper right triangle.[/quote]

This does not seem to be the case in my root version (5.34/02):

root [0] #include <TMatrixDSym.h>
root [1] TMatrixDSym C(2);
root [2] TMatrixDSym A(2);
root [3] TMatrixDSym B(2);
root [4] C = A + B;
root [5] C.Print();

2x2 matrix is as follows

     |      0    |      1    |
-------------------------------
   0 |          0           0 
   1 |          0           0 

root [6] A(1,0) = 1
(const int)1
root [7] A.Print();

2x2 matrix is as follows

     |      0    |      1    |
-------------------------------
   0 |          0           0 
   1 |          1           0 

root [8] C = A + B;
root [9] C.Print();

2x2 matrix is as follows

     |      0    |      1    |
-------------------------------
   0 |          0           0 
   1 |          1           0 

kind regards

Moritz Nadler

I additionally tried TMatrixDSym::Plus which is explicitly called “Symmetric matrix summation. Create a matrix C such that C = A + B.” in the root documentation but still:

root [0] #include <TMatrixDSym.h>
root [1] TMatrixDSym A(2);
root [2] TMatrixDSym B(2);
root [3] TMatrixDSym C(2);
root [4] C.Plus(A,B)
root [5] C.Print();

2x2 matrix is as follows

     |      0    |      1    |
-------------------------------
   0 |          0           0 
   1 |          0           0 

root [6] A(1,0) = 1;
root [7] A.Print();

2x2 matrix is as follows

     |      0    |      1    |
-------------------------------
   0 |          0           0 
   1 |          1           0 

root [8] C.Plus(A,B);
root [9] C.Print();

2x2 matrix is as follows

     |      0    |      1    |
-------------------------------
   0 |          0           0 
   1 |          1           0 

You confirmed my statement:

You filled the lower left triangle.

The operator(i,j} should be changed so that whatever you put in i,j will also
be inserted in j,i.

Sorry I am confused: you said

Which I thought means: Anything in the lower left triangle will be ignored by multiplication, adding , inversion , etc.

So I put something in the lower left of a sym. matrix A add onther matrix B and this something is not ignored by the Plus member function.

Maybe this example shows more clearly what I mean:

root [0] #include <TMatrixDSym.h>
root [1] TMatrixDSym A(2);
root [2] TMatrixDSym B(2);
root [3] TMatrixDSym C(2);
root [4] B(0,1) = 2;
root [5] A(1,0) = 1
(const int)1
root [6] C.Plus(A,B);
root [7] C.Print();

2x2 matrix is as follows

 |      0    |      1    |

0 | 0 2
1 | 1 0

you can see nothing is ignored all elements are used by the TMatrixDSym::Plus function no matter if they are in the lower left or upper right of the matrix.

kind regards

Moritz Nadler