-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject2_main.cpp
More file actions
64 lines (53 loc) · 2.02 KB
/
project2_main.cpp
File metadata and controls
64 lines (53 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Projekt nr 2 Metody Numeryczne
// Monika Drozd
#include "Rownanie.h"
#include <iostream>
#include <time.h>
using namespace std;
float liczCzas(Rownanie& eq, void(Rownanie::* initF)(), double(Rownanie::* methodF)());
// A - macierz o rozmiarze N x N gdzie N = 9cd
// c = 6, d = 8, e = 7, f = 5
// N = 9cd = 968
#define N 968
int main()
{
// Zadanie A - tworzenie ukladu rownan
Rownanie eq(N);
/*
cout << "Zadanie B, iteracje:" << endl;
cout << "Jacobi: " << liczCzas(eq, &Rownanie::initA, &Rownanie::metodaJacobiego) << "s" << endl;
cout << "Gauss-Seidl: " << liczCzas(eq, &Rownanie::initA, &Rownanie::metodaGaussaSeidla) << "s" << endl;
cout << "Zadanie C, zmiana a1: nie zbiegaja sie" << endl;
eq.initC();
cout << eq.metodaJacobiego();
eq.initC();
cout << eq.metodaGaussaSeidla();
*/
cout << "Zadanie D, LU:" << endl;
cout << endl << liczCzas(eq, &Rownanie::initC, &Rownanie::metodaLU) << "s" << "Norma z residuum uzywajac LU wynosi: " << endl;
cout << "Zadanie E:" << endl;
int arrN[] = { 100, 500, 968, 1000, 2000, 3000, 5000 };
int nSize = sizeof(arrN)/sizeof(arrN[0]);
cout << "Metoda Jacobiego:" << endl;
for (int i = 0; i < nSize; i++) {
Rownanie X(arrN[i]);
cout << "N = " << arrN[i] << " czas: " << liczCzas(X, &Rownanie::initA, &Rownanie::metodaJacobiego) << "s" << endl;
}
cout << endl << "Metoda Gaussa-Seidla:" << endl;
for (int i = 0; i < nSize; i++) {
Rownanie X(arrN[i]);
cout << "N = " << arrN[i] << " czas: " << liczCzas(X, &Rownanie::initA, &Rownanie::metodaGaussaSeidla) << "s" << endl;
}
cout << endl << "Metoda LU:" << endl;
for (int i = 0; i < nSize; i++) {
Rownanie X(arrN[i]);
cout << "N = " << arrN[i] << " czas: " << liczCzas(X, &Rownanie::initA, &Rownanie::metodaLU) << "s" << endl;
}
return 0;
}
float liczCzas(Rownanie& eq, void(Rownanie::* initF)(), double(Rownanie::* methodX)()) {
(eq.*initF)();
int start = clock();
cout << (eq.*methodX)() << " iteracje, ";
return (float)(clock() - start) / CLOCKS_PER_SEC;
}