The elimination element method of Gaussian column main element

Source: Internet
Author: User

Principle:
First row of the largest element of the first column is placed on the first line (on the first main element), with the largest element of the first column of the other elements into 0;
Compare the first element to zero the second element of the row, Repeat the above steps by placing the large in the first line except the first line (that is, after the first row (transformed) is transparent and no longer participates in the operation). The
is finally brought back to solve.

#include "stdafx.h" #include "stdio.h" #include "math.h" int main () {double m,p,a[10][10],x[10];
   int n,i,j,k,q;
   char c;  printf ("Please enter the order of the equation (less than or equal to 8): \ n");
   8 is because (1) rows and columns are both starting from 1 (2) and the constant number scanf ("%d", &n) on the right side;
     Enter the augmented matrix for (i=1;i<=n;i++)//from a[1][1] to deposit data {printf ("Please enter the augmented matrix%d line: \ n", i);
   for (j=1;j<=n+1;j++) scanf ("%lf", &a[i][j]);   }//For (i=1;i<n;i++) {m=fabs (a[i][i]); j=i; m represents the maximum value in the remaining column I, J is used to mark the maximum number of rows for (k=i+1;k<=n;k++) {if (Fabs (A[k][i]) >m) {M=fabs (a[k][i
      ]); j=k;}
        }//Exchange line, put the largest J row in each need to eliminate the first line for (q=i;q<=n+1;q++) {p=a[i][q];
        A[I][Q]=A[J][Q];
      A[j][q]=p; }//Eliminate the process for (k=i+1;k<=n;k++) {m=-a[k][i]/a[i][i];//to zero the column except for the largest element of the element into zeros for (j=i;j&lt
      ; =n+1;j++) A[k][j]=a[k][j]+a[i][j]*m;
      }}//****** return process ****** x[n]=a[n][n+1]/a[n][n]; for (i=n-1;i>=1;i--) {p=0.0;
        for (j=i+1;j<=n;j++) p=p+a[i][j]*x[j];
      x[i]= (a[i][n+1]-p)/a[i][i];
   }//for printf ("The solution of a linear equation group is: \ n");
   for (i=1;i<=n;i++) printf ("x[%d]=%.3lf\n", I,x[i]);
   C=getchar ();
return 0;
 }

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.