Home » C++ » relaxation iteration m

relaxation iteration m

recently used the relaxation method, called "Fang", to deepen memory, it is recorded,


/************************************************************************/
/* relaxation method for solving equations */
/************************************************************************/
#include
#include
Using namespace std;
const, float, w = 1.4;
double x[4] = {0};
double d = 0;
double SOR (double, a[][4], double, b[4])
{
int q = 0, i;
double c[4] = {0};
double x[4] = {0};
double t[4] = {0};
while (1)
{
Q++;
T[0] = (1 - W) *x[0] + w* (b[0] - a[0][1]*x[1] - a[0][2]*x[2] - a[0][3]*x[3]) /a[0][0];
T[1] = (1 - W) *x[1] + w* (b[1] - a[1][0]*t[0] - a[1][2]*x[2] -a[1][3]*x[3] /a[< span>1][1]);
T[2] = (1 - W) *x[2] + w* (b[2] - a[2][0]*t[0] - a[2][1]*t[1] - a[2][3]*x[3]) /a[2][2]; t[3] = (1 - W) *x[3] + w* (b[3] - a[3][0]*t[0] - a[3][1]*t[1] - a[3][< span>2]*t[2] /a[3][3]);
for (int I = 0; I < 4; i++)
{
C[i] = Fabs (t[i] - x[i]);
}
D = c[0];
for (I = 1; I < 4; i++)
{
if (d < c[i])
{
D = c[i];
}
}
for (I = 0; I < 4; i++)
{
X[i] = t[i];
}
if (d < 0.00001)
{
Cout<< "the number of iterations is:" <for (int I = 0; I < 4; i++)
{
Cout< "t" ;
}
break;
}
}
return 0;
}
void, main ()
{
int n;
double A[4][4] = {5, 1, -1, -2, 2, 8, 1, 3, 1, -2, -4, -1, -1, 3, 2, 7};
double, b[4] = {-2, -6, 6, 12};
double c[4] = {0};
double x[4] = {0};
double m[4] = {0};
double t[4] = {0};
SOR (A, B);
}

Latest