[Numerical] Why is it better to solve Ax=b instead of calculating inv(A)

  • Thread starter nonequilibrium
  • Start date
  • Tags
    Numerical
In summary, the conversation discusses the use of numerical methods to solve a matrix equation and the advantages of using Gaussian elimination and LU decomposition over calculating the inverse matrix. The benefits include improved stability, accuracy, and faster computation time. The conversation also mentions that explicitly inverting a matrix numerically is not recommended unless there is a specific reason for doing so.
  • #1
nonequilibrium
1,439
2
Hello,

So I'm using a numerical method where I iteratively have to solve [itex]Ax_{i+1}=x_i[/itex] which can of course be done by calculating the inverse matrix, but something in the back of my mind is telling me that it is better to solve the equation using Gaussian elimination and substitution.

However, what is the reason for this? And is the difference relevant, or is merely a difference "in principle".
 
Mathematics news on Phys.org
  • #2
There are lots of reasons not to use the inverse. Stability, accuracy, time. However, some of these reasons apply to a one-time solution of [itex]Ax=b[/itex]. Here you are apparently reusing the A matrix, iteratively solving [itex]Ax_{i+1} = x_i[/itex]. If you reuse A, timing considerations suggest you should compute the inverse of A instead of using Gaussian elimination.

There's an even better approach to using either of the techniques you mentioned. Compute the LU decomposition. It's cheaper to compute the LU decomposition than it is to use Gaussian elimination or the matrix inverse. LU backsubstitution is fast, faster than the matrix * vector computation, and the same stability and accuracy advantages that pertain to Gaussian elimination apply to LU decomposition.
 
Last edited:
  • #3
The iteration usually takes only three steps though, so maybe it is not evident that the inverse is optimal relative to solving it by Gaussian elimination?

Interesting what you say about the LU decomposition...
 
  • #4
Calculating the inverse efficiently (i.e. by doing an LU decomposition and then solving N right hand sides each containng one 1 and the rest of the entries 0) is an overhead of about N solves. So if you are only doing 3 solves anyway, you will lose unless N is very small.

In addition to D.H's points, often A is sparse and the LU decomposition has a similar amount of sparsity, but the inverse matrix is almost always fully populated. In that situation, multiplying by the inverse can be orders of magnitude more expensive than solving using the sparse matrices, quite apart from the numerical conditoning issues and the amount of storage that may be required for the inverse matrix.

My "rule of thumb" here is that explicitly inverting a matrix numerically is NEVER the right thing to do, unless you can make a very good argument in favor of it. Even when it appears to be "no worse" than equation solving, straightforward equation solving (based on LU decomoposition for example) is usually not the only alternative.
 
  • #5
Thank you both for the good advice.
 

1. Why is it better to solve Ax=b instead of calculating inv(A)?

When solving a system of linear equations, it is often more efficient to use matrix multiplication to solve for x rather than calculating the inverse of the coefficient matrix A. This is because calculating the inverse of a matrix can be computationally expensive and prone to rounding errors, while using matrix multiplication is simpler and more accurate.

2. What is the difference between solving Ax=b and calculating inv(A)?

Solving Ax=b involves multiplying the coefficient matrix A by the vector x to obtain the solution vector b. This is a more direct and efficient approach, as it only requires one matrix multiplication. On the other hand, calculating inv(A) involves finding the inverse of the coefficient matrix A, which can be a more complex and computationally intensive process.

3. Are there any cases where it is better to calculate inv(A) instead of solving Ax=b?

In some cases, such as when the matrix A is sparse or has a special structure, it may be more efficient to calculate the inverse of A and then use it to solve the system Ax=b. However, these cases are rare and in general, it is still more efficient and accurate to solve Ax=b directly.

4. How does solving Ax=b relate to other methods for solving systems of linear equations?

Solving Ax=b is one of the most commonly used methods for solving a system of linear equations. Other methods include Gaussian elimination, LU decomposition, and Cholesky decomposition. Each method has its own advantages and disadvantages, but solving Ax=b is often preferred due to its simplicity and efficiency.

5. Can solving Ax=b be used for systems with multiple variables and equations?

Yes, solving Ax=b can be used for systems with any number of variables and equations. As long as the coefficient matrix A is square and invertible, the system can be solved using this method. However, as the number of variables and equations increases, the computational complexity of solving Ax=b may also increase, making it less efficient for larger systems.

Similar threads

  • General Math
Replies
11
Views
1K
  • Atomic and Condensed Matter
Replies
4
Views
1K
  • General Math
Replies
1
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
854
Replies
1
Views
1K
Replies
14
Views
2K
  • Introductory Physics Homework Help
Replies
19
Views
1K
Replies
2
Views
1K
Replies
1
Views
5K
Back
Top