Which algorithm you would recommend for fast solution of dense linear system of fixed dimension (N=9) (matrix is symmetric, positive-semidefinite)?
- Gaussian elimination
- LU decomposition
- Cholesky decomposition
- etc?
Types are 32 and 64 bits floating points.
Such systems will be solved millions of times, so algorithm should be rather fast with respect to dimension (n=9).
P.S. examples of robust C++ implementations for proposed algorithm are appreciated.
1) What do you mean by “solved million of times”? Same coefficient matrix with a million of different right hand terms, or a million of distinct matrices?
Million of distinct matrices.
2) Positive _semi_definite means that matrix can be singular (to machine precision). How would you like to deal with this case? Just raise an error, or try to return some sensible answer?
Raising error is OK.
The matrix being symmetric, positive-semidefinite, the Cholesky decomposition is strictly superior to the LU decomposition. (roughly twice faster than LU, whatever the size of the matrix. Source : “Numerical Linear Algebra” by Trefethen and Bau)
It is also de facto the standard for small dense matrices (source : I do a PhD in computational mathematics) Iterative methods are less efficient than direct methods unless the system becomes large enough (quick rule of thumb that means nothing, but that is always nice to have : on any modern computer, any matrix smaller than 100*100 is definitely a small matrix that needs direct methods, rather than iterative ones)
Now, I do not recommend to do it yourself. There are tons of good libraries out there that have been thoroughly tested. But if I have to recommend you one, it would be Eigen :
By the way, here in the documentation, you have the various pros and cons of their 7 direct linear solvers in a nice, concise table. It seems that in your case, LDLT (a variation of Cholesky) wins