c++ code for inverse of NXN matrix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drsunil
    New Member
    • Mar 2008
    • 1

    #1

    c++ code for inverse of NXN matrix

    I need c++ code for inverse of nxn matrix ,if available please help me
  • sanctus
    New Member
    • Mar 2007
    • 84

    #2
    Originally posted by drsunil
    I need c++ code for inverse of nxn matrix ,if available please help me
    I do not know if it is exists for general case. For the 2X2 matrix there is the gsl library. If you have matlab you can call matlab to invert the matrix from your c++ code...

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Never invert a square matric explicitly: it is highly numerically unstable. A much
      better method is to find two triangular matrixes L and U (lower and upper triangular
      respectively where L has just ones (1) on its diagonal such that L.U == P.A
      where P is a row permutation matrix, Given L, U and P it is extremely easy
      to solve the linear system A.x == b.

      P.A.x == P.b (swap the elements in b)
      L.U.x == P.b
      L.y == P.b (by using a simple backward substitution)
      U.x == y (by using a simple forward substitution).

      Calculate x for the unit vectors b and voila.

      Google for "LUP decomposition" for the gory details.

      kind regards,

      Jos

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        See if you can convert this PHP code to C++

        Regards

        Comment

        Working...