#define eps 1e-10 #define maxn 110 double equ[maxn][maxn], ans[maxn]; int n; bool Gauss(){ for( int i = 0; i < n; i ++ ){ int pos = i; double res = fabs(equ[i][i]); for( int j = i + 1; j < n; j ++ ) if( fabs(equ[j][i]) > res ) pos = j, res = fabs(equ[j][i]); if( res < eps ) return false; if( pos != i ) for( int j = i; j<= n; j ++ ) swap(equ[i][j], equ[pos][j]); for( j = i + 1; j < n; j ++ ){ res = equ[j][i] / equ[i][i]; for( int k = i; k <= n; k ++ ) equ[j][k] -= res * equ[i][k]; } } for( i = n - 1; i >= 0; i -- ) { ans[i] = equ[i][n]; for( int j = n - 1; j > i; j -- ) ans[i] -= equ[i][j] * ans[j]; ans[i] /= equ[i][i]; } return true; }
作者:MetalSeed 发表于2013-2-4 23:32:36 原文链接
阅读:0 评论:0 查看评论