-added first stage of gauss

This commit is contained in:
Patrice Matz 2017-10-30 23:05:55 +01:00
parent a0e91b0365
commit 3bc8b5bd11
3 changed files with 50 additions and 9 deletions

View File

@ -13,7 +13,7 @@ int main()
{
cout << "Was wollen Sie tun ?" << endl;
cout << "1 Berechungen an einem Zylinder" << endl;
cout << "2 LGS lösen" << endl;
cout << "2 LGS loesen" << endl;
cout << "e Beenden" << endl;

View File

@ -12,9 +12,7 @@ void LGS::data_entry()
cout << "Anzahl der Unbekannten: "; cin >> variables;
creat_array();
cout << "Geben Sie die Gleichungen nach folgendem Schema an:" << endl;
cout << "[A1 *x][B1 *y][C1 *z]=[D1]" << endl;
cout << "[A2 *x][B2 *y][C2 *z]=[D2]" << endl;
cout << "[A3 *x][B3 *y][C3 *z]=[D3]" << endl;
print_exp();
for (int i = 0; i < variables; ++i)
{
@ -34,7 +32,7 @@ void LGS::data_entry()
}
cout << endl;
gauss_down();
}
void LGS::creat_array()
@ -50,7 +48,7 @@ void LGS::print()
{
for (int n = 0; n < variables + 1; ++n)
{
cout << GA[i][n] << " ";
cout << (GA[i][n] > 0 ? (n == 0 ? " " : " +") : " ") << GA[i][n] << " ";
if (n == variables-1)
cout << "= ";
}
@ -63,13 +61,30 @@ void LGS::print_ln(int ln)
for (int n = 0; n < variables + 1; ++n)
{
int var = 123 - variables + n;
cout << " +" << GA[ln][n] << (var!=123 ? (char)var : ' ');
cout << (GA[ln][n] > 0 ? (n==0 ? " " : " +"): " ") << GA[ln][n] << (var!=123 ? (char)var : ' ');
if (n == variables - 1)
cout << "= ";
}
cout << endl;
}
void LGS::print_exp()
{
for (int i = 0; i < variables; ++i)
{
for (int n = 0; n < variables + 1; ++n)
{
int var1 = n + 65;
int var2 = 123 - variables + n;
cout << "[" << (char)var1 << i + 1; var2!=123 ? cout<< (" *") : cout << ""; var2 != 123 ? cout << (char)var2 : cout << ""; cout << "]";
if (n == variables - 1)
cout << "= ";
}
cout << endl;
}
}
float LGS::cramer()
{
double t1 = clock();
@ -80,10 +95,33 @@ float LGS::cramer()
float LGS::gauss()
{
double t1 = clock();
gauss_down();
gauss_up();
return (float)((clock() - t1) / CLOCKS_PER_SEC);
}
void LGS::gauss_down( )
{
for(int stage = 1; stage < (variables==2 ? variables : variables-1) ; stage++)
{
long double div = (GA[stage][stage-1] / GA[stage-1][stage-1]);
for (int i = 0; i < variables-1; i++)
{
for (int n = 0; n <= variables; n++)
{
GA[stage + i][n] = GA[stage + i][n] - (GA[stage - 1][n] * div);
}
}
print();
cout << endl;
}
}

View File

@ -19,4 +19,7 @@ public:
void creat_array();
void print();
void print_ln(int);
void print_exp();
void gauss_down();
void gauss_up(){};
};