Sign in to follow this  
schupf

Solving linear equations

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 this post


Link to post
Share on other sites
Quote:
Original post by schupf
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).


#2 is faster.

Quote:
Original post by schupf
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?


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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this