Based on our study of the Gaussian elimination method in the Linear Algebra and its application, we give a programming realization of the unique solution of the linear equation Group.
The reference code is as follows:
typedefDoubleMATRIX[MAXN][MAXN];//a[][] is an augmented matrix, and the final a[i][n] represents the value of the first variablevoidGauss_elimination (Matrix A,intN) { intI, J, K, R; for(i =0; i < n;i++)//The step type of the rows{R=i; for(j = i +1; J < n;j++)//when the number of rows below line I is eliminated, the number of r lines of non-zero in column I is referred to line I if(Fabs (A[j][i]) > Fabs (a[r][i]) r=J; if(r! =i) for(j =0; J <= n;j++) Swap (a[r][j],a[i][j]); for(k = i +1; k < n;k++)//the elimination of the I+1~n row i { Doublef = a[k][i]/A[i][i]; for(j = i;j <= n;j++) A[K][J]-= f *A[i][j]; } } //The unique solution vectors are returned based on the row ladder type for(i = n-1; I >=0; i--) { for(j = i+1; J < n;j++) A[i][n]-= a[j][n] *A[i][j]; A[i][n]/=A[i][i]; }}
"Training Guide"--7.20