Gauss Seidal
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
double x1 = 1, x2 = 0, x3 = 1;
double e1, e2, e3;
double a, b, c, x, y, z;
int iteration;
printf("\nEnter the number of iteration=\n ");
// iteration = int.Parse(Console.ReadLine());
scanf("%d",&iteration);
for (int i = 0; i < 6; i++)
{
printf("\nIteration= %d" + i);
a = x1;
x1 = (1 - 3 * x2 + 5 * x3) / 12;
e1 = ((x1 - a) / x1) * 100;
//x = Math.Abs(e1);
if (e1 < 0)
{
e1 = e1 * -1;
}
x = e1;
b = x2;
x2 = (28 - x1 - 3 * x3) / 5;
e2 = ((x2 - b) / x2) * 100;
//y = Math.Abs(e2);
if (e2 < 0)
{
e2 = e2 * -1;
}
y = e2;
c = x3;
x3 = (76 - 3 * x1 - 7 * x2) / 13;
e3 = ((x3 - c) / x3) * 100;
//z = Math.Abs(e3);
if (e3 < 0)
{
e3 = e3 * -1;
}
z = e3;
printf("\nx1= %f" , x1);
printf("\nx2= %f" , x2);
printf("\nx3=%f ",x3);
printf("\ne1=%f " , x);
printf("\ne2=%f " , y);
printf("\ne3=%f " , z);
if (x > y)
{
if (x > z)
{printf("\nMax error %f" , x);}
else
{ printf("\nMax error %f" , z);}
}
else
{
if (y > z)
{printf("\nMax error %f" , y);}
else { printf("\nMax error %f" , z); }
}
}
getche();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
double x1 = 1, x2 = 0, x3 = 1;
double e1, e2, e3;
double a, b, c, x, y, z;
int iteration;
printf("\nEnter the number of iteration=\n ");
// iteration = int.Parse(Console.ReadLine());
scanf("%d",&iteration);
for (int i = 0; i < 6; i++)
{
printf("\nIteration= %d" + i);
a = x1;
x1 = (1 - 3 * x2 + 5 * x3) / 12;
e1 = ((x1 - a) / x1) * 100;
//x = Math.Abs(e1);
if (e1 < 0)
{
e1 = e1 * -1;
}
x = e1;
b = x2;
x2 = (28 - x1 - 3 * x3) / 5;
e2 = ((x2 - b) / x2) * 100;
//y = Math.Abs(e2);
if (e2 < 0)
{
e2 = e2 * -1;
}
y = e2;
c = x3;
x3 = (76 - 3 * x1 - 7 * x2) / 13;
e3 = ((x3 - c) / x3) * 100;
//z = Math.Abs(e3);
if (e3 < 0)
{
e3 = e3 * -1;
}
z = e3;
printf("\nx1= %f" , x1);
printf("\nx2= %f" , x2);
printf("\nx3=%f ",x3);
printf("\ne1=%f " , x);
printf("\ne2=%f " , y);
printf("\ne3=%f " , z);
if (x > y)
{
if (x > z)
{printf("\nMax error %f" , x);}
else
{ printf("\nMax error %f" , z);}
}
else
{
if (y > z)
{printf("\nMax error %f" , y);}
else { printf("\nMax error %f" , z); }
}
}
getche();
}
No comments:
Post a Comment