The use of Gauss elimination method in C language _c language

Source: Internet
Author: User

People who have studied mathematics know that the Gauss elimination method is the solution of linear equations, the algorithm is very simple, but the process is very complex, this is the online I can not find free and correct Gauss Elimination of the reasons for the method. So I made up my mind to make up my own, results I do it.
Gauss elimination method is widely used, it is one of the most important ways to solve mathematical problems, in the first chapter of this book is the Gauss elimination method, many problems finally boil down to the solution of the linear method group.
Because I am a beginner in programming, this program may seem funny to the master. But I don't mind, and I'd like you to give me a lot of advice.
I this program is compiled in C language, other languages have not been studied, the University of non-computer major students generally only learn C language, so this program is very suitable for students.
I hope that the university can point out the shortcomings of my procedures, and give me more advice, thank you.

Copy Code code as follows:

#include "Stdio.h"
#include "Conio.h"
/*l is the row minus 1 of the Matrix, which is the number of outermost loops from the program.
N the number of rows of the corresponding matrix and the number of columns of the m corresponding matrix
You can control the order of moments by changing L, N, and M.
#define L 3
#define N 4
#define M 5
void Gauss (double a[n][m],double x[n])
{int i,j,l,n,m,k=0;
Double Temp[n];
/* The first do-while is to eliminate the augmented matrix into the upper triangular form.
do{n=0;
for (l=k;l<l;l++) temp[n++]=a[l+1][k]/a[k][k];
for (m=0,i=k;i<n;i++,m++)
for (j=k;j<m;j++) a[i+1][j]-=temp[m]*a[k][j];
k++;
}while (K<n);
/* The second do-while is to convert the matrix to a diagonal form and to assign K again.
K=L-1;
do{n=0;
for (l=k;l>=0;l--) temp[n++]=a[k-l][k+1]/a[k+1][k+1];
For (m=0,i=k;i>=0;i--, m++)
for (j=k;j<m;j++) a[k-i][j]-=temp[m]*a[k+1][j];
k--;
}while (k>=0);
/* The next for is the solution Equation Group * *
for (i=0;i<n;i++) x[i]=a[i][n]/a[i][i];

}
void menu ()
{printf ("\ n _ _ _ _ _\n");
printf ("1.operation\n");
printf ("2.exit");
printf ("\ n _ _ _ _ _\n");
}
Main ()
{int i,j,choose;
Double A[n][m]={0},answer[n];
CLRSCR ();
while (1) {
Leep:menu ();
scanf ("%d", &choose);
Switch (choose) {
Case 1:
printf ("!! The size of Maxrix is%d *%d,each line Enter%d element:\n ", n,m,m);
for (i=0;i<n;i++)
{printf ("Enter the Matrix ' s%d line:\n", i);
for (j=0;j<n+1;j++)
scanf ("%lf", &a[i][j]);
}
printf ("\nthe Corss Matrix Is:\n_ _ _ _ _\n");
Gauss (A,answer);
for (i=0;i<n;i++)
{for (j=0;j<m;j++)
printf ("%-2lf", A[i][j]);
Putchar (' \ n ');
}
printf ("_ _ _ _ _ _\nthe Solve is:\n");
for (i=0;i<n;i++) printf ("x%d=%lf\n", I+1,answer[i]);
Case 2:
Exit (0);
default:printf ("Input error:\n"); goto leep;
}
}
Getch ();
}
/* Test:
Xi ' an Jiaotong University Press published in the "Calculation Method" book 28 pages of Example 2.1:
2 3-4-2
_-3-4-12 13 5
A= 2 10 0-3 10
14 9-13 7
Test results: x1=1,x2=2,x3=3,x4=4 * *


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.