I've implemented the matrix inversion in C, but it is too slow. Does anyone know a good free C source for matrix inversion?
C-source of matrix inversion
Started by ●October 28, 2005
Reply by ●October 28, 20052005-10-28
I'm no expert mathematician but .... Can you not use the Fortran LAPACK library? Have a look at this page: http://www.csit.fsu.edu/~burkardt/f_src/lapack/lapack.html Note the comments that if you wanted to convert the code to C, then the linpack library is easier to understand. If you don't want to work out how to call the LAPACK routines from C, there are many wrapper libraries out there that will do that for you. Cheers, Ross-c
Reply by ●October 28, 20052005-10-28
lanbaba wrote:> I've implemented the matrix inversion in C, but it is too slow. Does > anyone know a good free C source for matrix inversion?Look on the NIST website for "TNT" (T-something Numerical Toolkit). It's all written in C++, they sacrificed _lots_ of readability for portability, but it's all there and it's worked for me in the past. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●October 29, 20052005-10-29
lanbaba wrote:> I've implemented the matrix inversion in C, but it is too slow. Does > anyone know a good free C source for matrix inversion?There is Chapter 2.3 in Numerical Recipes in C: http://www.library.cornell.edu/nr/cbookcpdf.html Also note the following chapters that discuss special matrices and their inversion. If your matrix has a special form, inverting it might be possible in a faster manner than with general LU decomposition.
Reply by ●October 31, 20052005-10-31
lanbaba wrote:> I've implemented the matrix inversion in C, but it is too slow. Does > anyone know a good free C source for matrix inversion?Question for the group: Is there really a practical situation where there is a *legitimate* reason to *actually invert* a matrix? Sure, the solution to the system Ax = b is given by A^-1 * b -- but that's just a question of naming it that way; we would *never* compute the inverse of A to multiply it by b -- we solve the system (using Gauss, or Cholesky, or whatever method is suitable depending on our matrix). As I recall it, *every single time* that I've seen a reference to the inverse of a matrix, when you look closer, you notice that one doesn't get to *actually* compute the inverse when applying the method. Often, we use the inverse of a matrix as part of the analytic development of some solution -- but then, at the point where we get to the solution, the inverse either disappeared from the expressions, or you get to something that does not require computing the inverse (e.g., something that can be expressed in terms of solving Ax=b and thus avoid computing A^-1) Am I overlooking something? Carlos --
Reply by ●November 1, 20052005-11-01
Carlos Moreno wrote:> lanbaba wrote: > >> I've implemented the matrix inversion in C, but it is too slow. Does >> anyone know a good free C source for matrix inversion? > > > Question for the group: > > Is there really a practical situation where there is a *legitimate* > reason to *actually invert* a matrix? > > Sure, the solution to the system Ax = b is given by A^-1 * b -- but > that's just a question of naming it that way; we would *never* compute > the inverse of A to multiply it by b -- we solve the system (using > Gauss, or Cholesky, or whatever method is suitable depending on our > matrix). > > As I recall it, *every single time* that I've seen a reference to > the inverse of a matrix, when you look closer, you notice that one > doesn't get to *actually* compute the inverse when applying the > method. > > Often, we use the inverse of a matrix as part of the analytic > development of some solution -- but then, at the point where we > get to the solution, the inverse either disappeared from the > expressions, or you get to something that does not require > computing the inverse (e.g., something that can be expressed > in terms of solving Ax=b and thus avoid computing A^-1) > > Am I overlooking something? > > Carlos > --I recall having occasion to invert a matrix and embed the inverted matrix in some code to solve Ax = b sorts of problems with a gazillion 'b' vectors and a (very) constant A. Damned if I can remember when or why, though. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●November 1, 20052005-11-01
Tim Wescott wrote:>> Question for the group: >> >> Is there really a practical situation where there is a *legitimate* >> reason to *actually invert* a matrix? >> [...] > > I recall having occasion to invert a matrix and embed the inverted > matrix in some code to solve Ax = b sorts of problems with a gazillion > 'b' vectors and a (very) constant A.That sounds like a not-too-unreasonable choice, but still, it's not the "standard" way to go about it -- I believe that's precisely the argument in favor of Cholesky or other methods to decompose A into lower- and upper-triangular form: you now solve only a couple of back-substitutions for each of the b's that you require. (right?) Carlos --
Reply by ●November 1, 20052005-11-01
>Is there really a practical situation where there is a *legitimate* >reason to *actually invert* a matrix?>CarlosHi Carlos, A good point! Actually what I really need in my application is inv(B)*A. In the C version of the LAPACK library that Ross-c mentioned, only inv(B)*A is implemented if I didn't miss anything. Cheers, Lanbaba
Reply by ●November 1, 20052005-11-01
Reply by ●November 2, 20052005-11-02
lanbaba wrote:> >Is there really a practical situation where there is a *legitimate* > >reason to *actually invert* a matrix? > > >Carlos > > > Hi Carlos, > > A good point! Actually what I really need in my application is inv(B)*A. > In the C version of the LAPACK library that Ross-c mentioned, only > inv(B)*A is implemented if I didn't miss anything. > > Cheers, LanbabaThe Fortran-to-C(++) conversions I have seen, have been very crude, to say the least. It might be that lots of the LAPACK variations have been hidden behind a C++ interface, but I haven't found a C/C++ version of LAPACK that seems trustworthy. What I have seen, is that Intel sells the LAPACK and BLAS libraries both for Linux and windows as part of the Math Kernel library, http://www.intel.com/cd/software/products/asmo-na/eng/219769.htm The price doesn't seem too bad either. Be aware, though, that some C/C++ compilers may already have this library included, before you buy a license. Rune






