# Solving linear equations

This topic is 3460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I have a system of linear equations in this form: A*x = d, where A is a matrix approximately in range of 5x5 up to 20x20. My first question: What is more efficient: 1) Calculating the inverse of A and solving for x with a simple matrix multiplication in this way: x = A^-1 * d, or 2) Directly solving the system of linear equations (with gauss elemination for example). And a little additional question to option 2: In the case I want to programm a solver for a system of linear equations in C++. What is the most efficient method? Gauss-Eleminition? Gauss-Jordan-Elimination? LU-Decomposition? Or something else? Thanks!

##### Share on other sites
Quote:
 Original post by schupfMy first question: What is more efficient: 1) Calculating the inverse of A and solving for x with a simple matrix multiplication in this way: x = A^-1 * d, or2) Directly solving the system of linear equations (with gauss elemination for example).

#2 is faster.

Quote:
 Original post by schupfAnd a little additional question to option 2: In the case I want to programm a solver for a system of linear equations in C++. What is the most efficient method? Gauss-Eleminition? Gauss-Jordan-Elimination? LU-Decomposition?

The LU Decomposition is computed using one of the elimination methods you mentioned, so it's not really a separate method. Anyway, Gaussian elimination is more efficient than Gauss-Jordan. The algorithm you want is "Gaussian Elimination with Pivoting."

(This ignores iterative algorithms like Gauss-Seidel and conjugate gradient... but for small matrices elimination algorithms are better anyway...)

##### Share on other sites
Quote:
 Original post by Emergent[...] The algorithm you want is "Gaussian Elimination with Pivoting."

To be more specific, you probably want "Gaussian Elimination with Partial Pivoting."

##### Share on other sites
#2 is indeed faster, and Gaussian Elimination with Partial Pivoting is indeed the most efficient algorithm. It is also numerically stable - inverting a matrix, especially up to 20x20, can be numerically dangerous.

1. 1
Rutin
67
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633416
• Total Posts
3011780
• ### Who's Online (See full list)

There are no registered users currently online

×