Solving linear equations with large matrices
显示 更早的评论
I have a simple equation of the form Ax = B; where A is a large dense matrix(nXn) and B is a column matrix (nX1).
A is hermitian but not symmetric positive definite.
I am proceeding through simple \ + 'qr' decomposition. However this method is quite inefficient as it is quite time consuming.
Moreover, the command is nested within two for loops each running ~300 times. This I effectively have to solve the linear equation 300x300 times.
Can anyone suggest a faster and better method?
6 个评论
Alex Mcaulley
2019-4-12
Have you tried this?
Srijeet Tripathy
2019-4-12
John D'Errico
2019-4-12
How large of a matrix are you talking about? Note that a significant number of people think that a 100x100 matrix is large. So just calling it large tells us nothing.
What does time consuming mean to you? I.e., how much time?
Do you have sufficient memory? Is your problem that you have insuifficient memory, and are thus incurring a problem because you just need more RAM? RAM is CHEAP these days, and getting cheaper every minute.
Is your matrix fairly well-conditioned? If it is, AND you are running low on memory, then use of single precision MIGHT offer some relief.
You could use a pivoted LU as an alternative to QR.
If your matrix solve is happening inside a loop, is the matrix constant? If so, then you really don't want to be computing a factorization multiple times. Instead, you just have one problem with 90000 right hand sides. Or, if you compute the factorization in advance, then appy it to each right hand side.
Sorry if these questions seem silly, or perhaps don't apply to you, but how can we know what the real issue is unless you provide sufficient information? And there are a lot of people who might ask exactly the questions you have asked, yet have no clue what they are doing.
Remember that an nxn matrix solve is an O(n^3) operation on a dense matrix, that will require a lot of memory. If you really do have a big problem with a matrix that changes at every point in those loops, you will just need to accept the big time it will require.
Steven Lord
2019-4-12
John asked several good questions; I want to focus on one. Is the matrix constant, with only the right hand side changing in the loops? If so, consider creating a decomposition of the matrix before the loop and solving using that decomposition inside.
Alternately if the matrix is changing inside the loops but only slightly and you expect the solution at one iteration is "close to" the solution at the next, maybe an iterative solver like gmres would help, using the solution from one iteration as the initial guess for the next. You may be able to take adantage of the structure of the coefficient matrix as well. If you can compute the product of the matrix with a vector without explicitly creating the matrix, you may be able to save some memory by passing a function handle into gmres or the other iterative solvers.
John D'Errico
2019-4-12
MATLAB already does the linear algebra on big problems in parallel, so it will automatically farm out the computation to as many cores as you have, or at least as many as you allow it to do so.
So check this at the command line:
maxNumCompThreads
It will tell you how many cores your computer has available.
And do you have a good CPU fan? This because running all of your CPU cores flat out will cause it to kick on full, and excessive heat will throttle down your CPU.
Do you have access to a more powerful computer? Are you willing to spend money to solve the problem, perhaps renting time on somethign seriously bigger? You need to recognize that sometimes a necessary tradeoff exists between $ and your own time.
Srijeet Tripathy
2019-4-12
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Linear Algebra 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!