I already doing it but I need a lot of help.
thanks
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...
I already doing it but I need a lot of help.
thanks
I figure you're gonna need a lot of functions that perform row-wise operations. Some rough codeIn 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).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; }
Last edited by QuestionC; 11-15-2001 at 08:28 AM.
Callou collei we'll code the way
Of prime numbers and pings!