99 lines
2.7 KiB
C++
Executable File
99 lines
2.7 KiB
C++
Executable File
#include <math.h>
|
|
#include "CMyVektor.h"
|
|
#include "CMyMatrix.h"
|
|
#include "C_DGLSolver.h"
|
|
#include <iostream>
|
|
using namespace std;
|
|
|
|
CMyVektor DGLSystem(CMyVektor y, double x) {
|
|
CMyVektor result(2);
|
|
result.setElement(1, 2 * y.getElement(2) - x * y.getElement(1));
|
|
result.setElement(2, y.getElement(1) * y.getElement(2) - 2 * pow(x, 3));
|
|
return result;
|
|
}
|
|
|
|
double DGL_dritter_Ordnung(CMyVektor y, double x) {
|
|
return 2 * x * y.getElement(2) * y.getElement(3) + 2 * pow(y.getElement(1), 2) * y.getElement(2);
|
|
}
|
|
|
|
int main() {
|
|
int option;
|
|
|
|
cout << "Was soll berechnet werden? \n" <<
|
|
"1 Euler-Verfahren DGL\n" <<
|
|
"2 Heun-Verfahren DGL\n" <<
|
|
"3 Abweichungen DGL 3.O\n" <<
|
|
"0 Beenden\n"
|
|
"> ";
|
|
cin >> option;
|
|
|
|
while (0 < option && option < 4) {
|
|
switch (option) {
|
|
case 1: {
|
|
CMyVektor startwerte(vector<double>{0, 1});
|
|
double xStart = 0; // x0 = 0
|
|
double xEnd = 2;
|
|
C_DGLSolver dglSystemTest(DGLSystem);
|
|
dglSystemTest.euler(startwerte, xStart, xEnd, 100);
|
|
break;
|
|
}
|
|
case 2: {
|
|
CMyVektor startwerte(vector<double>{0, 1});
|
|
double xStart = 0; // x0 = 0
|
|
double xEnd = 2;
|
|
C_DGLSolver dglSystemTest(DGLSystem);
|
|
dglSystemTest.heun(startwerte, xStart, xEnd, 100);
|
|
break;
|
|
}
|
|
case 3: {
|
|
CMyVektor startwerte(3);
|
|
CMyVektor eulerResult(3);
|
|
CMyVektor heunResult(3);
|
|
CMyVektor allResults(8);
|
|
C_DGLSolver dglSystemTest(DGL_dritter_Ordnung);
|
|
|
|
|
|
double schritte;
|
|
double xStart;
|
|
double xEnd;
|
|
int j = 1;
|
|
for (int i = 1; i < 5; i++) {
|
|
schritte = pow(10, i);
|
|
xStart = 1;
|
|
xEnd = 2;
|
|
startwerte.setElements(vector<double>{1, -1, 2});
|
|
eulerResult = dglSystemTest.euler(startwerte, xStart, xEnd, schritte);
|
|
allResults.setElement(j, eulerResult.getElement(1) - 0.5);
|
|
|
|
startwerte.setElements(vector<double>{1, -1, 2});
|
|
heunResult = dglSystemTest.heun(startwerte, xStart, xEnd, schritte);
|
|
allResults.setElement(++j, heunResult.getElement(1) - 0.5);
|
|
j++;
|
|
}
|
|
cout << endl;
|
|
int k = 1;
|
|
cout << setw(10) << "Verfahren" << setw(10) << "Schritte" << setw(10) << "Δ\n";
|
|
for (int j = 1; j <= 4; j++) {
|
|
double schritte = pow(10, j);
|
|
// E = s+1 , H = E*2
|
|
cout << setw(10) << "Euler" << setw(10) << setprecision(0) << schritte << setw(10) << scientific << setprecision(1) << allResults.getElement(k) << endl;
|
|
cout << setw(10) << "Heun" << setw(10) << setprecision(0) << schritte << setw(10) << scientific << setprecision(1) << allResults.getElement(++k) << endl << endl;
|
|
|
|
k++;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
cout << "\nHauptmenü: \n" <<
|
|
"1 Euler-Verfahren DGL\n" <<
|
|
"2 Heun-Verfahren DGL\n" <<
|
|
"3 Euler/Heun Vergleich DGL 3.O\n" <<
|
|
"0 Beenden\n"
|
|
"> ";
|
|
cin >> option;
|
|
|
|
};
|
|
cout << endl << endl;
|
|
system("PAUSE");
|
|
} |