CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2009
    Posts
    27

    Inverse of a Matrix: Efficient Code (timewise)

    I need to find the inverse of a matrix which contains floating point numbers. Can anyone share an efficient (w.r.t. time) code?

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Inverse of a Matrix: Efficient Code (timewise)

    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Inverse of a Matrix: Efficient Code (timewise)

    http://people.richland.edu/james/lec.../inverses.html
    http://www.wikihow.com/Inverse-a-3X3-Matrix
    http://mathworld.wolfram.com/MatrixInverse.html
    http://www.mathwords.com/i/inverse_of_a_matrix.htm

    For small matrixes, efficiency is a bit of a moot issue since there's very little you can do to optimise things. You can typically get the best results by hardcoding a function for a specific matrix size not using any loops. This will quickly become unwieldy as your matrix size increases. But for 2x2, 3x3 and 4x4 it's definately worth the effort. I would expect a performance oriented 3D lib to have such hardcoded matrix calculations since they typically only have to deal with 1 size matrix.

    For large matrixes, there are a number of systems that have varying degrees of performance over the raw calculation.

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Inverse of a Matrix: Efficient Code (timewise)

    Usually the fastest approach involves some form of matrix decomposition. LU, SVD, or Cholesky decompositions are common.

    As noted, these are probably overkill for small matrices.

  5. #5
    Join Date
    Apr 2009
    Posts
    27

    Re: Inverse of a Matrix: Efficient Code (timewise)

    I was aiming for a range of 24X24.

    I found a file through Google:
    http://users.erols.com/mdinolfo/matrix.htm

    He's shown an example with 200x200. In that regard I have a naive question to ask:
    If I include a header file, but delete all but a single function out of that header file, will my .exe be as large as it would have been if I had used the entire header file? In both cases I am using the same function, but in the first case I am removing the extra baggage. Does the compiler understand and reduce the compiled code?

  6. #6
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Inverse of a Matrix: Efficient Code (timewise)

    Compilers are usually pretty good about trimming unused code, especially in a non-DLL context. However, unless you're working on an embedded platform, exe size should be fairly low down your list of priorities IMO.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured