Chapter:

gauss-elimination-method

1. SOLVE THE SYSTEM OF LINEAR EQUATIONS USING GAUSS ELIMINATION METHOD

TITLE: 

TO  SOLVE THE SYSTEM OF LINEAR EQUATIONS USING GAUSS ELIMINATION METHOD

 OBJECTIVES:

  • To be able to follow the algorithm of Gauss Elimination method of solving linear equation.

  • To build some programming concepts by solving practical problems.

 TOOLS REQUIRED:

  • Computer workstation

  • Program software (as necessary)

 THEORY:

Gaussian elimination method is an algorithm for solving systems of the linear equations, and finding the rank of a matrix, and calculating the inverse of an invertible square matrix. Gaussian elimination is named after the German mathematician and the scientist Carl Friedrich Gauss.

Gauss elimination is an exact method which solves a given system of equation in n unknowns by transforming the coefficient matrix, into an upper triangular matrix and then solve for the unknowns by back substitution.

The process of Gaussian elimination has two parts. The first part (Forward Elimination) reduces a given system to either triangular or echelon form, or results in a degenerate equation with no solution, indicating the system has no solution. This is done through the use of elementary. The second step uses back substitution to find the solution of the system above. The first part reduces a matrix to row echelon form using elementary row operations while the second reduces it to reduced row echelon form, or row canonical form.


 ALGORITHM:

  • Write the augmented matrix for the system of the linear equations.

  • Use elementary row operations on the augmented matrix [A|b] to the transform of A into the upper triangular form. If the zero is locate on the diagonal, switch the rows until a nonzero is in that place. If we are unable to do so, stop; the system has either infinite or has no solutions.

  • Use the back substitution going to find the solution of the problem.

#include
#include
#include
#define   SIZE   10
Void main()
{
	 float a[SIZE][SIZE], x[SIZE], ratio;
	 int i,j,k,n;
	 clrscr();
	 fflush (stdout);
	 printf("Enter number of unknowns: ");
	 scanf("%d", &n);
	 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();
 }

CONCLUSION:

Thus the system of given linear equations were solved using Gauss Elimination Method using C programming language.



Show More