How to use function 'eigenvalues' from the stan math library

Dear community

I am kind of new in Stan. I need to calculate eigenvalues and eigenvectors of non-symmetric matrices. I saw that there are two functions in the stan math library called ‘eigenvalues’ and ‘eigenvectors’. I have tried to follow the external C++ examples, but I have not been able to make them work.
Could anybody explain me in an easy way what to do?

Thank you,
Alex

2 Likes

The first question is: Is there some special condition that is going to guarantee these asymmetric matrices have real eigenvalues? Or are you going to have to deal with complex numbers (in which case, the version of Stan Math you are working with matters)?

Let’s say that I will put limits to the parameters’ values to make sure that non complex eigenvalues are involved. Also I would like to add that the operation that I would like to do is the generalized eigenvalue decomposition.

For a generalized eigenvector problem with no structure on the input matrices, I think you would have to write a C++ function that wraps

http://eigen.tuxfamily.org/dox/classEigen_1_1RealQZ.html

but you would have to do some stuff to get the generalized eigenvalues without introducing std::complex. Or use a recent enough Stan Math that has complex number support, call the regular generalized eigensolver in Eigen, and throw away the imaginary parts (which should be numerically zero).