Bug fix in gauss

This commit is contained in:
madmaurice 2016-02-15 13:01:02 +01:00
parent 7bb2c09a2c
commit 6e26844a6f

16
gauss.c
View file

@ -102,15 +102,16 @@ int solve_gauss_rec(GLS m, int rowCol) {
if( ISZERO(glsGet(m,rowCol,rowCol)) ) return 0;
for(size_t row = rowCol+1; row < m.size; row++) {
if(ISZERO(glsGet(m,row, rowCol))) continue;
glsTransform(m, row, glsGet(m,rowCol,rowCol), rowCol, - glsGet(m,row,rowCol) );
if(!ISZERO(glsGet(m,row, rowCol)))
glsTransform(m, row, glsGet(m,rowCol,rowCol), rowCol, - glsGet(m,row,rowCol) );
glsSet(m,row,rowCol, 0.0f);
}
if(!solve_gauss_rec(m, rowCol+1)) return 0;
for(size_t row = 0; row < rowCol; row--) {
glsTransform(m, row, glsGet(m,rowCol,rowCol), rowCol, - glsGet(m,row,rowCol) );
for(size_t row = 0; row < rowCol; row++) {
if(!ISZERO(glsGet(m,row,rowCol)))
glsTransform(m, row, glsGet(m,rowCol,rowCol), rowCol, - glsGet(m,row,rowCol) );
glsSet(m,row,rowCol, 0.0f);
}
@ -129,9 +130,10 @@ int solve(GLS m) {
int main( int argc, char *argv[] ) {
GLS m = glsCreate(2);
glsSet(m,0,0,2); glsSet(m,0,1,3); glsSetRS(m,0, 13);
glsSet(m,1,0,1); glsSet(m,1,1,2); glsSetRS(m,1, 8);
GLS m = glsCreate(3);
glsSet(m,0,0,3); glsSet(m,0,1,-1); glsSet(m,0,2,-1); glsSetRS(m,0, 0);
glsSet(m,1,0,1); glsSet(m,1,1,4); glsSet(m,1,2,2); glsSetRS(m,1, 4);
glsSet(m,2,0,0); glsSet(m,2,1,2); glsSet(m,2,2,1); glsSetRS(m,2, 1);
printf("Input: \n");
glsPrint(m);