Gauss Elimination Method Algorithm

 

Gauss Elimination Method Algorithm

In linear algebra, Gauss Elimination Method is a procedure for solving systems of linear equation. It is also known as Row Reduction Technique. In this method, the problem of systems of linear equation having n unknown variables, matrix having rows n and columns n+1 is formed. This matrix is also known as Augmented Matrix. After forming n x n+1 matrix, matrix is transformed to upper trainagular matrix by row operations. Finally result is obtained by Back Substitution.

Algorithm for Gauss Elimination Method

1. Start

2. Read Number of Unknowns: n

3. Read Augmented Matrix (A) of n by n+1 Size

4. Transform Augmented Matrix (A) to Upper Trainagular Matrix by Row Operations.

5. Obtain Solution by Back Substitution.

6. Display Result.

7. Stop

Gauss Elimination Method Algorithm
Gauss Elimination Method Algorithm


we are going to develop pseudocode for this method so that it will be easy while implementing using programming language. Pseudocode is a detailed yet readable description of what a computer program or algorithm should do. It is written in a formal yet readable style that uses a natural syntax and formatting so it can be easily understood by programmers and others involved in the development process.

1. Start

2. Input the Augmented Coefficients Matrix (A):

For i = 1 to n

For j = 1 to n+1

Read Ai,j

Next j

Next i

3. Apply Gauss Elimination on Matrix A:

For i = 1 to n-1

If Ai,i = 0

Print "Mathematical Error!"

Stop

End If

For j = i+1 to n

Ratio = Aj,i/Ai,i

For k = 1 to n+1

Aj,k = Aj,k - Ratio * Ai,k

Next k

Next j

Next i

4. Obtaining Solution by Back Substitution:

Xn = An,n+1/An,n

For i = n-1 to 1 (Step: -1)

Xi = Ai,n+1

For j = i+1 to n

Xi = Xi - Ai,j * Xj

Next j

Xi = Xi/Ai,i

Next i

5. Display Solution:

For i = 1 to n

Print Xi

Next i

6. Stop

---------------

Note: All array indexes are assumed to start from 1.

Gauss Elimination Method Using C

Earlier in Gauss Elimination Method Algorithm and Gauss Elimination Method Pseudocode , we discussed about an algorithm and pseudocode for solving systems of linear equation using Gauss Elimination Method. we are going to implement this method using C programming language.

Complete Program for Gauss Elimination method using C Programming Language

#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<stdlib.h>

#define SIZE 10

int main()

{

float a[SIZE][SIZE], x[SIZE], ratio;

int i,j,k,n;

clrscr();

/* Inputs */

/* 1. Reading number of unknowns */

printf("Enter number of unknowns: ");

scanf("%d", &n);

/* 2. Reading Augmented Matrix */

for(i=1;i<=n;i++)

{

for(j=1;j<=n+1;j++)

{

printf("a[%d][%d] = ",i,j);

scanf("%f", &a[i][j]);

}

}

/* Applying Gauss Elimination */

for(i=1;i<=n-1;i++)

{

if(a[i][i] == 0.0)

{

printf("Mathematical Error!");

exit(0);

}

for(j=i+1;j<=n;j++)

{

ratio = a[j][i]/a[i][i];

for(k=1;k<=n+1;k++)

{

a[j][k] = a[j][k] - ratio*a[i][k];

}

}

}

/* Obtaining Solution by Back Subsitution */

x[n] = a[n][n+1]/a[n][n];

for(i=n-1;i>=1;i--)

{

x[i] = a[i][n+1];

for(j=i+1;j<=n;j++)

{

x[i] = x[i] - a[i][j]*x[j];

}

x[i] = x[i]/a[i][i];

}

/* Displaying Solution */

printf("\nSolution:\n");

for(i=1;i<=n;i++)

{

printf("x[%d] = %0.3f\n",i, x[i]);

}

getch();

return(0);

}

Output: Gauss Elimination Method for Solving Systems of Linear Equations

Enter number of unknowns: 3

a[1][1] = 1

a[1][2] = 1

a[1][3] = 1

a[1][4] = 9

a[2][1] = 2

a[2][2] = -3

a[2][3] = 4

a[2][4] = 13

a[3][1] = 3

a[3][2] = 4

a[3][3] = 5

a[3][4] = 40

Solution:

x[1] = 1.000

x[2] = 3.000

x[3] = 5.000

Post a Comment

0 Comments