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:
find the solutions of a set at simultaneous equation using gauss seidal method
pls give me c program for fitting a polynomial of a second order
wrong !!! completely wrong
wrong !!! completely wrong
this is giving completely wrong answer....
i get the correct ans actually~
thnks hemant its really a good one .....and i think u r a good programmer.........thnks a lot.
the program is nt running....der's sum errors....wad cud it b?
the program is nt runnin....wad is d error?????
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.
I get the smell of Windows from your program.
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
Post a Comment