Eigenvalues from TMatrixD

I have a loop where I am updating a TMatrixD H every iteration. I would like to get the eigenvalues each time through. From reading the documentation it appears that to do this I must call TMatrixDEigen(H) every iteration and then get the individual vectors.

I haven’t looked at the code, but since this is a constructor and not a method, do I have to manually clean up each time? Is there a better way to do this?
Chris

Hi Chris,

I am not sure I understand your question .
Since it is a constructor, there is no need for a cleanup inside the loop.

In the constructor, the necessary memory is allocated to store the
eigen -values and -vectors and the quantities are calculated.

One could think of some additional functionality like in the
decompostion classes so that the space allocation is separated
from the calculation . This way one can pull out the construction
of the TMatrixDEigen out of the loop and do the allocation only
once . However, most time is of course in the calculation .

Eddy

Hi Eddie,
Thanks for the quick reply.

I’ve attached a code sample at the end. The important question is here:

for(i=0;i<NPoints;i++)
{
// Modify H and then get the eigenvalues.
// Won’t this allocate new private variables on the stack on each call?
TMatrixDEigen EG(H);
ev = EG.GetEigenValuesRe();
energy1[i] = ev[0];
energy2[i] = ev[1];
}

Regards
Chris
energy2.C (2.38 KB)

Hi Chris,

Your code looks fine: First modify H, create a TMatrixDEigen object,
copy the eigenvalues . At the end of the loop the TMatrixDEigen
object runs out of the scope and gets destroyed .

Eddy

Thanks for the sanity check.
Regards,
Chris