Which solver should I use to solve a square and symmetric, linear system of equations?
Show older comments
I want to solve a linear system of equations which is always square and symmetric. So far I always use mldivide ("backslash"). However, I was wondering if there is an even more efficient solver when I can assure that the matrix is always symmetric? I saw for example that there is a solver called SYMMLQ which seems to be especially designed for symmetric matrices (I actually have not that many mathematical knowledge about solvers). Is this one maybe interesting for my case?
Accepted Answer
More Answers (3)
Bruno Luong
on 16 Mar 2022
Edited: Bruno Luong
on 16 Mar 2022
Don't worry, MATLAB backslash detects automatically the type of your matrix and adapt the method. See "Algorithm" of doc page
All you need to do is make sure your matrix is exactly symmetric and not approximately. In case you have a doubt run as preprocess
A = 0.5*(A+A').
R = chol(A);
x = R\(R'\b)
I don't know if it's faster than the usual \.
2 Comments
Bruno Luong
on 16 Mar 2022
chol requires matrix to be semi definite positive, I don't see OP state that.
Torsten
on 16 Mar 2022
Ok, then you might want to test first for positive definiteness:
[R,flag] = chol(A)
if flag
x = R\(R'\b);
end
I don't have experience with SYMMLQ, but since it's iterative, I suspect that - under the aspect of efficiency - it comes into play only for really large problems.
Steven Lord
on 16 Mar 2022
0 votes
You could call linsolve and tell linsolve explicitly that your coefficient matrix is symmetric.
If you have a sparse system of linear equations you could use symmlq.
If you're solving multiple systems with the same coefficient matrix but a collection of different right-hand sides you could create a decomposition object and tell it to use a specific decomposition ('chol' if the coefficient matrix is SPD, 'ldl' if it's just symmetric but not positive definite, etc.)
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!