问题:1、列主消元为什么精度高?
2、fabs函数精确度
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn=109; const double eps=1e-10; int n; double a[maxn][maxn]; inline double douabs(double x){ if(x<0)return -x; else return x; } int Gauss(){ for(int j=1;j<=n;++j){ int maxline=j; for(int i=j+1;i<=n;++i){ if(douabs(a[i][j])>douabs(a[maxline][j]))maxline=i; } if(maxline!=j){ for(int k=j;k<=n+1;++k)swap(a[j][k],a[maxline][k]); } if(douabs(a[j][j])<eps)return 0; for(int i=j+1;i<=n;++i){ double tmp=a[i][j]/a[j][j]; for(int k=j;k<=n+1;++k){ a[i][k]=a[i][k]-tmp*a[j][k]; } } } for(int i=n;i>=1;--i){ for(int j=i+1;j<=n;++j){ a[i][n+1]=a[i][n+1]-a[i][j]*a[j][n+1]; } a[i][n+1]/=a[i][i]; } } int main(){ scanf("%d",&n); for(int i=1;i<=n;++i){ for(int j=1;j<=n+1;++j){ scanf("%lf",&a[i][j]); } } if(Gauss()==0){ printf("No Solution "); }else{ for(int i=1;i<=n;++i)printf("%.2f ",a[i][n+1]); } return 0; }