# Can I tell ROOT "this matrix is symmetric"?

Hi, I find the documentation of the linear algebra classes a bit lacking making it hard to figure out how to use them in the first place, and good practices thereafter. Once I have stuff figured out it usually is easy, though, and I really enjoy using it.

I have the following problem: speaking intuitively, I want to convert a covariance matrix C to a different coordinate system. This means sandwiching C between the linearized transformation matrix A and its transposed A^T, i.e. C’ = ACA^T. Now, since C is symmetric, positive (semi-)definite, C’ is as well. Is there a way to tell ROOT that a matrix expression is symmetric, even though the individual factors aren’t?

I.e., I want to express the fact that something like

```TMatrixDSym D = TMatrixDSym (A, TMatrixD::kMult, TMatrixD (C, TMatrixD::kMultTranspose, A)); ```
does indeed give a symmetric matric (the example gives a nice series of C++ errors). Alternatively, I’m looking for a way to convert a TMatrixT to a TMatrixTSym.

(There’s also

`enum EMatrixCreatorsOp1 { kZero,kUnit,kTransposed,kInverted,kAtA };` in TMatrixT.h, so I could perhaps take the square root of C (i.e. its Cholesky decomposition), multiply the decomposition matrix U with A^T from above, and then multiply the resulting matrix with itself via TMatrixT::kAtA to obtain the symmetric matrix I’m after. Not really elegant, and I couldn’t find any documentation indicating whether kAtA really does what I think it does.)

Hi,

Have a look at the following functions in the TMatrixDSym class:

``````  TMatrixTSym<Element>  &Similarity    (const TMatrixT   <Element> &n);
TMatrixTSym<Element>  &Similarity    (const TMatrixTSym<Element> &n);
TMatrixTSym<Element>  &SimilarityT   (const TMatrixT   <Element> &n);``````

So in your case do :

``TMatrixDSym D = C.Similarity(A);``

It is not allowed otherwise to create a symmetric matrix from a general
one . Of course, one can by pass this through a constructor like

``TMatrixTSym<double>(Int_t row_lwb, Int_t row_upb, const double* data, Option_t* option = "")``

Eddy

Thanks a bunch, that’s precisely what I want.