# Which solver should I use to solve a square and symmetric, linear system of equations?

조회 수: 9(최근 30일)
Michael Loibl 2022년 3월 16일
답변: Steven Lord 2022년 3월 16일
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?

댓글을 달려면 로그인하십시오.

### 채택된 답변

Christine Tobler 2022년 3월 16일
The first thing to check is the size and density of your matrix. The SYMMLQ function you mentioned is one of a group of methods for iteratively solving sparse linear systems (see doc), which should be used if your linear system is large and sparse (that is, around 1e4-by-1e4 at least to have a good likelyhood to be faster.
For a dense matrix, or for many sparse matrices, it's simpler and faster to use backslash. If A is real and exactly symmetric (issymmetric returns true), mldivide will use a symmetric algorithm if appropriate. You can symmetrize A in advance like Bruno suggests, which will backslash to always use a symmetric algorithm - in particular if your matrix is symmetric positive or negative definite, this is likely to help with performance since Cholesky is used in mldivide just as Torsten demonstrated.

댓글을 달려면 로그인하십시오.

### 추가 답변(3개)

Bruno Luong 2022년 3월 16일
편집: Bruno Luong 2022년 3월 16일
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').
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

Torsten 2022년 3월 16일
편집: Torsten 2022년 3월 16일
R = chol(A);
x = R\(R'\b)
I don't know if it's faster than the usual \.
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Torsten 2022년 3월 16일
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 2022년 3월 16일
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.)

댓글을 달려면 로그인하십시오.

### 범주

Find more on Linear Algebra in Help Center and File Exchange

R2019b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by