Computer Oriented Numerical Methods 4
Computer Oriented Numerical Methods 4
CODE:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void main()
{
float a[10][10], b[10], x[10], xn[10], epp=0.00001, sum;
int i, j, n, flag;
13
x[i]=0; //initialize
/* testing of diagonal dominance may be included here from
the program of Gauss-Jacobi's method */
do{
for(i=0;i<n;i++)
{
sum=b[i];
for(j=0;j<n;j++)
{
if(j<i)
sum-=a[i][j]*xn[j];
else if(j>i)
sum-=a[i][j]*x[j];
xn[i]=sum/a[i][j];
}
}
flag=0; // indicates |x[i]-xn[i]|<epp for all i
for(i=0;i<n;i++)
if(fabs(x[i]-xn[i])>epp)
flag=1;
if(flag==1)
for(i=0;i<n;i++)
x[i]=xn[i]; // reset x[i]
}while(flag==1);
printf("Solution is \n");
for(i=0;i<n;i++)
printf("%8.5f ",xn[i]);
}
OUTPUT:
COMMENTS:
In this lab, we learned the iterative process of solving a set of linear algebraic equation using Gauss-Seidel
Method by writing C-codes. Before the start of the process of iteration, the algorithm for partial pivoting
was carried out as given above. Then written codes were tested for different sets of equation. This was
done on the fourth day of the lab.
14