Gauss Seidal Method

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

/*************** Prog.

for Gauss Seidal Method ****************/

void main()
{
int i,j,n,count;
float error;
double x1,x2,x3,x4,x5,a[10][10];
printf("\nenter the augmented matrix of order 3*(3+1)");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
scanf("%lf",&a[i][j]);
}
}
printf("\nenter the prescribed error tolerance");
scanf("%f",&error);
printf("\nenter the no of iterations");
scanf("%d",&n);
printf("\nenter the initial approximation");
scanf("%lf%lf",&x2,&x3);
if(a[0][0]==0||a[1][1]==0||a[2][2]==0)
{
printf("\nuse pivoting");
}
else
{
for(i=1;i<=n;i++)
{
x1=-((a[0][1]*x2)+(a[0][2]*x3))/a[0][0]+(a[0][3]/a[0][0]);
x4=-((a[1][0]*x1)+(a[1][2]*x3))/a[1][1]+(a[1][3]/a[1][1]);
x5=-((a[2][0]*x1)+(a[2][1]*x2))/a[2][2]+(a[2][3]/a[2][2]);
printf("\n%d\t%lf\t%lf\t%lf",i,x1,x2,x3);
if(fabs(x2-x4) {
count=0;
break;
}
else
{
x1=x1;
x2=x4;
x3=x5;
}
}
}
if(count==0)
{
printf("\nconverges in%diterationsx=%lf\ty=%lf\tz=%lf",i,x1,x4,x5);
}
else
{
printf("\nincrease the no of iterations");
}
getche();
}

You might also like