-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
103 lines (86 loc) · 3.48 KB
/
main.cpp
File metadata and controls
103 lines (86 loc) · 3.48 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include "include/function.h"
#include "include/numericalDiff/finiteDiff.h"
#include "include/numericalDiff/finiteDiffTaylor.h"
#include "include/numericalDiff/finiteDiffNewton.h"
void CLS()
{
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
using namespace std;
/*
Anotações:
para h = 1^-10, as derivadas primeiras convergem bem
para h = 1^-6, as derivadas segundas convergem bem
para h = 1^-1 e h=1^-2, as derivadas terceiras convergem bem
para h = 1^-1 e h=1^-2, as derivadas quartas convergem bem
quanto maior o h (para h < 1), mais a convergência melhora para as derivadas
terceiras e quartas (erro propagado e muitas subtrações)
*/
// main somente para testes
int main()
{
CLS();
// x, h, filosofia, Fx, ordem da derivada
float x, h, result;
int order, option;
cout << "Entre o valor de x: ";
cin >> x;
cout << "Entre o valor de h: ";
cin >> h;
/*
cout << "Entre a ordem da derivada: ";
cin >> order;
cout << "Escolha a filosofia: \n 0 - Fw \n 1 - Bw \n 2 - Ct \n";
cin >> option;
switch (option)
{
case 0:
result = forwardRec(x, h, order);
break;
case 1:
result = backwardRec(x, h, order);
break;
case 2:
result = centralRec(x, h, order);
break;
}
*/
CLS();
cout << "x: " << x << endl;
cout << "h: " << h << endl;
cout << "=====================================" << endl;
cout << "firstForward: " << firstForwardDerivation(x, h) << endl;
cout << "firstCentral: " << firstCentralDerivation(x, h) << endl;
cout << "firstBackward: " << firstBackwardDerivation(x, h) << endl;
cout << "TaylorLinear: " << firstTaylorDerivation_LinearErrorAndForward(x, h).derivateValue << endl;
cout << "TaylorQuadratic: " << firstTaylorDerivation_QuadraticErrorAndForward(x, h).derivateValue << endl;
cout << "TaylorCubic: " << firstTaylorDerivation_CubicErrorAndForward(x, h).derivateValue << endl;
cout << "=====================================" << endl;
cout << "secondForward: " << secondForwardDerivation(x, h) << endl;
cout << "secondCentral: " << secondCentralDerivation(x, h) << endl;
cout << "secondBackward: " << secondBackwardDerivation(x, h) << endl;
cout << "secondForwardRec: " << forwardRec(x, h, 2) << endl;
cout << "secondCentralRec: " << backwardRec(x, h, 2) << endl;
cout << "secondBackwardRec: " << centralRec(x, h, 2) << endl;
cout << "secondNewton: " << secondNewtonDerivation_fourthOrder(x, h) << endl;
cout << "=====================================" << endl;
cout << "thirdForward: " << thirdForwardDerivation(x, h) << endl;
cout << "thirdCentral: " << thirdCentralDerivation(x, h) << endl;
cout << "thirdBackward: " << thirdBackwardDerivation(x, h) << endl;
cout << "thirdForwardRec: " << forwardRec(x, h, 3) << endl;
cout << "thirdCentralRec: " << backwardRec(x, h, 3) << endl;
cout << "thirdBackwardRec: " << centralRec(x, h, 3) << endl;
cout << "=====================================" << endl;
cout << "fourthForward: " << fourthForwardDerivation(x, h) << endl;
cout << "fourthCentral: " << fourthCentralDerivation(x, h) << endl;
cout << "fourthBackward: " << fourthBackwardDerivation(x, h) << endl;
cout << "fourthForwardRec: " << forwardRec(x, h, 4) << endl;
cout << "fourthCentralRec: " << backwardRec(x, h, 4) << endl;
cout << "fourthBackwardRec: " << centralRec(x, h, 4) << endl;
return 0;
}