how to do an inverse of a matrix using gauss elimination algorithm?

This is a discussion on how to do an inverse of a matrix using gauss elimination algorithm? within the C Programming forums, part of the General Programming Boards category; I already doing it but I need a lot of help. thanks...

  1. #1
    Unregistered
    Guest

    how to do an inverse of a matrix using gauss elimination algorithm?

    I already doing it but I need a lot of help.

    thanks

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    I figure you're gonna need a lot of functions that perform row-wise operations. Some rough code
    Code:
    int main ()
    {
     int * m, * identity;
     int aspect, i, temp;
    
     getMatrix (&m, &aspect);
     makeIdentity (&identity, aspect);
    
     // Now we have 2 matrices.  Let's do the math...
    
     for (i = 0; i < aspect; i++)
     {
      // Selects a row such that the ith element of the row is not 0
      j = getithRow (m);
      /* Example, performed on matrix:
       0 5 6
       3 4 5
       2 3 5
       will return 1... */
    
      if (j != i)
      {
       // Anything we do to one matrix, we do to the other.
       swapRows (m, j, i);
       swapRows (identity, j, i);
      }
      /* 3 4 5   0 1 0
         0 5 6   1 0 0
         2 3 5   0 0 1 */
    
      temp = m[i][i];
      divideRow (m, i, temp);
      divideRow (identity, i, temp);
      /* 1 1.33 1.67       0    0  .33
         0    5    6       1    0    0 
         2    3    5       0    1    0 */
      
      for (j = 0; j < aspect; j++)
      {
       temp = m[j][i];
       // This function does a lot, it subtracts 
       //   from row j, row i's values times temp.
       subRow (m, j, i, temp);
      }
      /* 1 1.33 1.67       0    0  .33
         0    5    6       1    0    0 
         0  .33 1.67       0    1  .66 */
     }  // Then you move on to the next row.
     return 0;
    }
    In addition to needing the functions, the code I posted will not work, but it should get the idea across (and it takes very little modification to repair).
    Last edited by QuestionC; 11-15-2001 at 07:28 AM.
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C program - inverse of a matrix
    By chaugh in forum C Programming
    Replies: 4
    Last Post: 01-18-2010, 10:00 PM
  2. Need to Calculate the Inverse of A Matrix.
    By jordan_230 in forum C Programming
    Replies: 6
    Last Post: 11-03-2008, 05:14 PM
  3. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 04:57 PM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21