-
Notifications
You must be signed in to change notification settings - Fork 0
/
Integral.cpp
68 lines (47 loc) · 1.63 KB
/
Integral.cpp
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
#include <iostream>
#include "src/CosineFunction.h"
#include "src/SineFunction.h"
#include "src/TrapezoidalRule.h"
#include "src/SimpsonRule.h"
#include "src/RombergMethod.h"
const double ACCURACY = 1e-4;
const double STEP_SIZE = 1e-4;
int main() {
double a = 0;
double b = 0.1;
std::cout << std::endl << "COSINE" << std::endl << std::endl;
CosineFunction cosine;
for (int i = 0; i < 10; i++) {
std::cout << "a = 0" << std::endl;
std::cout << "b = " << b << std::endl;
TrapezoidalRule trapezoidalRule(STEP_SIZE);
SimpsonRule simpsonRule(STEP_SIZE);
RombergMethod rombergMethod(ACCURACY);
std::cout << "Trapezoidal Rule == ";
std::cout << trapezoidalRule.calculate(cosine, a, b) << std::endl;
std::cout << "Simpson's Rule == ";
std::cout << simpsonRule.calculate(cosine, a, b) << std::endl;
std::cout << "Romberg's Method == ";
std::cout << rombergMethod.calculate(cosine, a, b) << std::endl;
std::cout << std::endl;
b += 0.1;
}
b = 0.1;
std::cout << std::endl << "SINE" << std::endl << std::endl;
SineFunction sine;
for (int i = 0; i < 10; i++, b += 0.1) {
std::cout << "a = 0" << std::endl;
std::cout << "b = " << b << std::endl;
TrapezoidalRule trapezoidalRule(STEP_SIZE);
SimpsonRule simpsonRule(STEP_SIZE);
RombergMethod rombergMethod(ACCURACY);
std::cout << "Trapezoidal Rule == ";
std::cout << trapezoidalRule.calculate(sine, a, b) << std::endl;
std::cout << "Simpson's Rule == ";
std::cout << simpsonRule.calculate(sine, a, b) << std::endl;
std::cout << "Romberg's Method == ";
std::cout << rombergMethod.calculate(sine, a, b) << std::endl;
std::cout << std::endl;
}
return 0;
}