"Training Guide"--7.20

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.