Gauss Elimination
Gauss Elimination
Gauss Elimination
ASSIGNMENT 8
TO SOLVE LINEAR ALGEBRIC EQUATION BY GAUSS ELIMINATION
METHOD
STATEMENT:
The Gauss Elimination method is a most common and useful method to find
the unknowns in a system of linear equations of the form:
a11x1+ a12x2+ a13x3+……..+ a1,n-1xn-1+a1,nxn = b1
a21x1+ a22x2+ a23x3+……..+ a2,n-1xn-1+a2,nxn = b2
a31x1+ a32x2+ a33x3+……..+ a3,n-1xn-1+a3,nxn = b3
………………………………………………….
an,1x1+ an,2x2+ an,3x3+……....+ an,n-1xn-1+ an,nxn = bn
where the principle diagonal elements of the co-efficient matrix of the system or
pivot elements aii ≠ 0 (i= 1,2,3,4,…..,n).
This method is based on the procedure to reduce the system of equations to
another system where the co-efficient matrix of new system is an upper triangular
matrix, by successive elimination of the unknowns then the values of the unknowns
are computed by backward substitution.
ALGORITHM:
INPUT: Co-efficient matrix of the system of the equation with right hand
side matrix
PROCESS:
Step 1.1: Take the order of the matrix in an integer type variable ‘n’.
Step 1.2: Take the co-efficient matrix with right hand side in an ‘float’ type
two dimensional array ‘a’.
Step 1.3: For k=0 to (n-2) repeat Step 1.4 to Step 1.7
Step 1.4: For i=(k+1) to (n-1) repeat Step 1.5 to Step 1.7
Step 1.14: Display the value of the unknowns by a ‘float’ type array ‘x’.
Step 2: Stop.
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main( )
{
float a[10][10],x[10],r;
int i,j,k,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<=n;j++)
{
printf("\n\t\tEnter the a[%d][%d]-th element:",i+1,j+1);
scanf("%f",&a[i][j]);
for(k=0;k<n-1;k++)
{
for(i=k+1;i<n;i++)
{
r=a[i][k]/a[k][k];
for(j=0;j<=n;j++)
a[i][j]=a[i][j]-a[k][j]*r;
}
}
x[n-1]=a[n-1][n]/a[n-1][n-1];
for(i=n-2;i>=0;i--)
{
x[i]=a[i][n];
for(j=n-1;j>i;j--)
x[i]=x[i]-a[i][j]*x[j];
x[i]=x[i]/a[i][i];
}
for(i=0;i<n;i++)
printf("\n\t\tx[%d]=%f\n\n\t\t",i+1,x[i]);
getch( );
}
34
PROGRAM OUTPUT:
DISCUSSION:
operations. This makes them totally impracticable, even on the fastest computers, as
soon as n ≥ 10.