How do I diagonalize a matrix quickly in C++?

笑着哭i 提交于 2019-12-11 04:09:34

问题


I don't know which library to choose (for windows): LAPACK++, Armadillo, IT++, Eigen, or maybe something else?

All I need to do is to check if a big (about 10,000*10,000) matrix is diagonalizable, and if so, to get the diagonal and the invertible matrix such that D=(P^(-1))*A*P. This has to be done as fast as possible. I have no idea which library to use.

Also, I'll be happy to know in general what are the pros and cons of each of these libraries.


回答1:


This may be a rather vague answer, since I don't know what exact problem you're up against, but it is very often the case that you don't actually need all that information, i.e. you only care about a matrix' eigenvalues with the most energy; and as for the rest - does it really matter if you have 0.001 as an eigenvalue (diagonalizable matrix) or 0.000 (non-diagonalizable)? For many real-world (and even theoretical) applications, the answer is 'not really'.

So, my suggestion is that you gain speed by giving up on the accuracy or granularity of the information you're looking for.




回答2:


You might want to take this with a grain of salt, but here are some benchmarks published by the developers of Eigen. I have never used any other linear algebra library besides Eigen, but your needs may differ from mine.




回答3:


As far as finding the determinant goes, there are a number of different implementations that you can use. One is to use Gaussian Elimination to create an upper/lower triangular matrix - this is beneficial in that you then just have to multiply on the diagonal to get the determinant. If any row or any column ends up zeroing out as a result, you will have a determinant of 0 and the matrix will not have an inverse. You could actually use this method and augmenting the matrix with an identity matrix and performing a full Gauss-Jordan elimination and turning the original matrix into an identity matrix as seen at http://www.mathportal.org/linear-algebra/matrices/gauss-jordan.php .



来源:https://stackoverflow.com/questions/19599284/how-do-i-diagonalize-a-matrix-quickly-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!