hye... guys i m new one in C++ and i have a matrix of size 96x48 (which is a non square matrix) i want to take inverse of this matrix .... please guide me ...thanks
- 3 Contributors
- forum2 Replies
- 54 Views
- 6 Years Discussion Span
- comment Latest Post by mike_2000_17
DeanMSands3 69
Did a little Google-fu. I found the Armadillo library hosted on Sourceforge. It has a Psuedo-Inverse function (http://arma.sourceforge.net/docs.html#pinv)
Also found a codeforge sample: http://www.codeforge.com/article/41545 - Might be more useful if you've never linked libraries.
(Disclaimer: This is Google-fu only. I haven't tested either.)
mike_2000_17 2,669
If your matrix is 96x48, then you cannot invert it. You have to solve the linear least-square problem, which leads to computing the left Moore-Penrose pseudoinverse. This can be calculated in a number of different ways, the more generic of which is the QR-decomposition, or the Singular Value Decomposition which is a lot more expensive computationally but more robust if the matrix is rank-deficient (or nearly so), but in this case, it is usually better to use an RRQR decomposition. These are all basic numerical methods that you will find in just about any matrix library out there, including mine.
Normally, however, you rarely calculate an inverse or a pseudoinverse of a matrix, because most of the time what you really want to do is solve a system of linear equations (either determined, under-determined (min-norm problem), or over-determined (least-square problem)). And if you are solving a system of linear equations, you should solve the system of linear equations directly, not through the calculation of an inverse or pseudo-inverse. The systems of linear equations are solved with the same method as for finding the inverse (i.e., the inverse is just the result of solving a system of linear equations where the right-hand side is the identity matrix), but it is quicker to do it in one step. And for that reason, most matrix libraries will provide both functions (and several others related to them). One example is my QR decomposition code which has several related functions like QR, RQ, RRQR and StrongRRQR decompositions, as well as upper / lower triangular back / forward substitution functions, which can be used to construct just about any kind of inversion or linear solution to equation system, least-square or minimum-norm.