Tuesday, November 27, 2007

Program in C for Gause Seidel method...

Though I am not smart programmer but still here is code in C for Gause Seidel method...

Important notes:
1. while running the program replace [] (in #include )by less than and greater than symbol since i cant publish post with those symbol.
2. if there is written like less than then use symbol in actual program.
/*program for guass siedel by Hemant Abhare. M.tech 1st year corrosion sci &
engg.Roll no:06316005*/
#include[stdio.h]
#include[conio.h]
#include[math.h]
#include[stdlib.h]
#define epsilon 1e-6
void main()
{
int i,j,n,k,m;
float sum,s,xi,d;
float x[20],a[20][20],b[1];
double e=0;
printf("\n ****Gauss Seidel Method**** ");
printf("\n Enter no. of eqn.: \t");
scanf("%d",&n);

printf("\n Enter Augumented matrix [A] :");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%f",&a[i][j]);
printf("\n a[%d][%d]=%f\n",i,j,a[i][j]);
}
{
scanf("%f",&b[i]);
printf("\n b[%d]=%f\n",i,b[i]);
}
}
printf("Enter the initial appx for
X(1),X(2),X(3)...\n");
for(i=1;i<=n;i++)
{
scanf("%f",&x[i]);
printf("\n x[%d]=%f\n",i,x[i]);
}
for(i=1;i<=n;i++)
{
if(a[i][i]==0)
printf("diagonal elements are zero,
solution not possible without pivoting\n");
}
do
{
m=1;
for(i=1;i<=n;i++)
{
s=0;
for(j=1;j<=n;j++)
if(i!=j)
s+=a[i][j]*x[j];
xi=(b[i]-s)/a[i][i];
printf("\n x[%d]=%f\n",i,xi);
d=fabs((xi-x[i]));
printf("d=%f\n",d);
x[i]=xi;
printf("x[%d]=%f\n",i,x[i]);
}
m++;
}
while ((d>= epsilon));
printf("\n Result :-");
for(i=1;i<=n;i++)
printf("\n x[%d]=%f ",i,x[i]);
}

14 comments:

mahendran said...

find the solutions of a set at simultaneous equation using gauss seidal method

Milind said...

pls give me c program for fitting a polynomial of a second order

tota said...

wrong !!! completely wrong

tota said...

wrong !!! completely wrong

Akash said...

this is giving completely wrong answer....

胡言乱语 said...

i get the correct ans actually~

mamta said...

thnks hemant its really a good one .....and i think u r a good programmer.........thnks a lot.

avynn said...

the program is nt running....der's sum errors....wad cud it b?

avynn said...

the program is nt runnin....wad is d error?????

Kajal said...

guys who have got wrong ans plz check with a matrix with a[1][1],a[2][2],a[3][3],... element of the matrix greater than the sum of the other elements of the corresponding row.

dE_logics said...

I get the smell of Windows from your program.

dE_logics said...
This comment has been removed by the author.
twilight said...
This comment has been removed by the author.
BSY333 said...

In the output i got enter the Augumented matrix
What is Augumented matrix for equation 2x1 + 3x2 + 5x3 = 23
3x1 + 4x2 + x3 = 14
6x1 + 7x2 + 2x3 = 26
Please email the solution at bsyadav51290@gmail.com