Friday, May 24, 2013

Gauss Jordan Method Implementation with C Source Code

In linear algebra, Gaussian Jordan method is an algorithm for solving systems of linear equations. It is usually understood as a sequence of operations performed on the associated matrix of coefficients. This method can also be used to find the rank of a matrix, to calculate the determinant of a matrix, and to calculate the inverse of an invertible square matrix.

We can implement this method in C using the following source code:
//Implementation of Gauss Jordan Method, @author: +Jivan Nepali, @URL: codeplustech
 #include<stdio.h>  
 #include<conio.h>  
 #include<stdlib.h>  
 #define Max 10  
 int main()  
 {  
   float a[Max][Max+1],t,det=1;  
   int i,j,k,N;  
   printf("Enter the number of unknowwns : ");  
   scanf("%d",&N);  
   
printf("\nEnter the elements of the augmented matrix :\n");  
   for(i=0;i<N;i++)  
     for(j=0;j<N+1;j++)  
       scanf("%f",&a[i][j]);  
   for(i=0;i<N;i++)  
     for(j=0;j<N;j++)  
       if(i!=j)  
         {  
           t=a[j][i]/a[i][i];  
           for(k=0;k<N+1;k++)  
             a[j][k]-=a[i][k]*t;  
         }  
   for(i=0;i<N;i++)  
     det*=a[i][i];  
   printf("\nDeterminant = %.4f\n",det);  
   if(det==0){  
     printf("\nThe matrix is singular .\n");  
     exit(1);  
     }  
   printf("\nThe Gauss-Jordan Matrix is :\n\n");  
   for(i=0;i<N;i++)  
   {  
     for(j=0;j<N+1;j++)  
       printf("%.4f ",a[i][j]);  
     printf("\n");  
   }  
   printf("\nThe solution is :\n\n");  
   for(i=0;i<N;i++)  
     printf("x[ %d]=%.4f\n",i+1,a[i][N]/a[i][i]);  
   getch();  
   return 0;  
 }  

Enjoy coding!!!

2 comments :

  1. Cosas interesantes que tienes y nos mantienes actualizándonos a todos. Metodo pose

    ReplyDelete
  2. as soon as I noticed this internet site I went on reddit to share some of the love with them. best iPhone cases

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...