Bug fix in gauss
This commit is contained in:
parent
7bb2c09a2c
commit
6e26844a6f
1 changed files with 9 additions and 7 deletions
16
gauss.c
16
gauss.c
|
@ -102,15 +102,16 @@ int solve_gauss_rec(GLS m, int rowCol) {
|
||||||
if( ISZERO(glsGet(m,rowCol,rowCol)) ) return 0;
|
if( ISZERO(glsGet(m,rowCol,rowCol)) ) return 0;
|
||||||
|
|
||||||
for(size_t row = rowCol+1; row < m.size; row++) {
|
for(size_t row = rowCol+1; row < m.size; row++) {
|
||||||
if(ISZERO(glsGet(m,row, rowCol))) continue;
|
if(!ISZERO(glsGet(m,row, rowCol)))
|
||||||
glsTransform(m, row, glsGet(m,rowCol,rowCol), rowCol, - glsGet(m,row,rowCol) );
|
glsTransform(m, row, glsGet(m,rowCol,rowCol), rowCol, - glsGet(m,row,rowCol) );
|
||||||
glsSet(m,row,rowCol, 0.0f);
|
glsSet(m,row,rowCol, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!solve_gauss_rec(m, rowCol+1)) return 0;
|
if(!solve_gauss_rec(m, rowCol+1)) return 0;
|
||||||
|
|
||||||
for(size_t row = 0; row < rowCol; row--) {
|
for(size_t row = 0; row < rowCol; row++) {
|
||||||
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);
|
glsSet(m,row,rowCol, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,9 +130,10 @@ int solve(GLS m) {
|
||||||
|
|
||||||
int main( int argc, char *argv[] ) {
|
int main( int argc, char *argv[] ) {
|
||||||
|
|
||||||
GLS m = glsCreate(2);
|
GLS m = glsCreate(3);
|
||||||
glsSet(m,0,0,2); glsSet(m,0,1,3); glsSetRS(m,0, 13);
|
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,2); glsSetRS(m,1, 8);
|
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");
|
printf("Input: \n");
|
||||||
glsPrint(m);
|
glsPrint(m);
|
||||||
|
|
Loading…
Reference in a new issue