Solving linear equations
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!
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...)
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."
#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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement