#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<conio.h>
void main(void)
{
int K, P, C, J;
double A[100][101];
int N;
int Row[100];
double X[100];
double SUM, M;
int T;
do
{
printf("Please enter number of equations [Not more than %d]\n",100);
scanf("%d", &N);
} while( N > 100);
printf("You say there are %d equations.\n", N);
printf("From AX = B enter elements of [A,B] row by row:\n");
for (K = 1; K <= N; K++)
{
for (J = 1; J <= N+1; J++)
{
printf(" For row %d enter element %d please :\n", K, J);
scanf("%lf", &A[K-1][J-1]);
}
}
for (J = 1; J<= N; J++) Row[J-1] = J - 1;
for (P = 1; P <= N - 1; P++)
{
for (K = P + 1; K <= N; K++)
{
if ( fabs(A[Row[K-1]][P-1]) > fabs(A[Row[P-1]][P-1]) )
{
T = Row[P-1];
Row[P-1] = Row[K-1];
Row[K-1] = T;
}
}
if (A[Row[P-1]][P-1] 0)
{
printf("The matrix is SINGULAR !\n");
printf("Cannot use algorithm --- exit\n");
exit(1);
}
X[N-1] = A[Row[N-1]][N] / A[Row[N-1]][N-1];
for (K = N - 1; K >= 1; K--)
{
SUM = 0;
for (C = K + 1; C <= N; C++)
{
SUM += A[Row[K-1]][C-1] * X[C-1];
}
X[K-1] = ( A[Row[K-1]][N] - SUM) / A[Row[K-1]][K-1];
}
for( K = 1; K <= N; K++)
printf("X[%d] = %lf\n", K, X[K-1]);
getch();
}
Chat with our AI personalities
Of course, Gaussian Elimination!
Gaussian elimination is used to solve systems of linear equations.
gauss
The gaussian elimination is used to solve many linear equations with many unknown varaibles at once. [See related link below to find out how to do it]. This is used alot by engineers you know ceratin variables in there structures and want to find out what the stress and strain is in certain areas. They make up there linear equations and then they can use the gaussian elimination method to find the unknown variables.
It solves a system of equations. Think of the 2X2 case of having X+Y=1 and 3X+2Y=6.