0% found this document useful (0 votes)
7 views4 pages

Lab 8

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Lab 8

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab 8: Gauss Jordan Method

Introduction
Gauss Jordan 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 diagonal matrix by row operations. Finally
result is obtained by making all diagonal element to 1 i.e. identity matrix.

Algorithm
Step 1: Start
Step 2: Read Dimension of System of equations, say n
Step 3: Read coefficient of augmented matrix row-wise
Step 4: Perform row operations to convert LHS of augmented matrix into identity
matrix
For k =1 to n
Pivot =a[k][k]
For p=1 to n+1
A[k][p] =a[k][p] / pivot
For I =1 to n
Term = [i][k]
If(I ≠k)
Multiply row k by “term” and subtract it from row i
End for
End for
Step 5: Display solution vector which is last column of augmented matrix
Step 6: Terminate

Program:
#include<stdio.h>
int main()
{
int i,j,k,n;
float A[20][20],c,x[10];
printf("\nEnter the size of matrix: ");
scanf("%d",&n);
printf("\nEnter the elements of augmented matrix row-wise:\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]);
}
}
/* Now finding the elements of diagonal matrix */
for(j=1; j<=n; j++)
{
for(i=1; i<=n; i++)
{
if(i!=j)
{
c=A[i][j]/A[j][j];
for(k=1; k<=n+1; k++)
{
A[i][k]=A[i][k]-c*A[j][k];
}
}
}
}
printf("\nThe solution is:\n");
for(i=1; i<=n; i++)
{
x[i]=A[i][n+1]/A[i][i];
printf("\n x%d=%f\n",i,x[i]);
}
return(0);
}
Output

You might also like