You are on page 1of 5

31

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

OUTPUT: Numerical value of the unknown variables in the system of


equation.

PROCESS:

Step 1: Create the function “void main()”

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.5: Set r  (a[i][k] / a[k][k])

Step 1.6: For j=0 to n repeat Step 1.7


32

Step 1.7: Set a[i][j]  a[i][j] −a[k][j] * r

[End of Step 1.6 ‘For’ loop]

[End of Step 1.4 ‘For’ loop]

[End of Step 1.3 ‘For’ loop]

Step 1.8: Set x[n-1]  (a[n-1][n] / a[n-1][n-1])

Step 1.9: For i=(n-2) to 0 repeat Step 1.10 to Step 1.13

Step 1.10: Set x[i]  a[i][n]

Step 1.11:For j= (n-1) to (i+1) repeat Step 1.12

Step 1.12: Set x[i]  x[i]−a[i][j] * x[j]

[End of Step 1.11 ‘For’ loop ]

Step 1.13: Set x[i]  (x[i] / a[i][i])

[End of Step 1.9 ‘For’ loop]

Step 1.14: Display the value of the unknowns by a ‘float’ type array ‘x’.

[End of the function “void main( )”]

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;

printf("\n\n\t\tEnter the order of the matrix:");

scanf("%d",&n);

printf("\n\n\t\tEnter the co-efficient matrix and Right Hand Side");


33

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];
}

printf("\n\n\t\tThe Solutions Are:\n");

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:

To perform row reduction on a matrix, one uses a sequence of elementary row


operations to modify the matrix until the lower left-hand corner of the matrix is
filled with zeros, as much as is possible. There are three types of elementary row
operations: 1) Swapping two rows, 2) Multiplying a row by a non-zero number, 3)
Adding a multiple of one row to another row. Using these operations a matrix can
always be transformed into an upper triangular matrix. It should be emphasized
that, for a n×n matrix, this method needs O(n3) arithmetic operations, while the
elementary methods, usually taught in elementary courses, need O(2n)) or O(n!)
35

operations. This makes them totally impracticable, even on the fastest computers, as
soon as n ≥ 10.

You might also like