-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnumericalintegration.cpp
More file actions
102 lines (81 loc) · 2.88 KB
/
numericalintegration.cpp
File metadata and controls
102 lines (81 loc) · 2.88 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
#include "numericalintegration.h"
NumericalIntegration::NumericalIntegration() {
chart = new QChart();
}// NumericalIntegration
void NumericalIntegration::computeGraphs(bool expression, bool rettangoli, bool trapezoidi, bool Simpson) {
if(expression) graphExpression();
if(rettangoli) graphRectangle();
if(trapezoidi) graphTrapezoidal();
if(Simpson) graphSimpson();
}// computeGraphs
void NumericalIntegration::graphExpression() {
expression->setX(from);
QSplineSeries *graph = new QSplineSeries();
graph->setName("Funzione");
for (int i = 0; i < gresolution; i++) {
*graph << QPointF(expression->getX(), expression->getY());
expression->addX(gdelta);
}
chart->addSeries(graph);
}// graphExpression
void NumericalIntegration::graphRectangle() {
NIResult result = NIMethods::rectangle(expression, from, to, resolution);
rectangleOut = result.first;
QLineSeries *qline = new QLineSeries;
qline->setName("Rettangoli");
for (auto e : result.second) *qline << QPointF(e.first, e.second);
chart->addSeries(qline);
}// graphRectangle
void NumericalIntegration::graphTrapezoidal() {
NIResult result = NIMethods::trapezoidal(expression, from, to, resolution);
trapezoidalOut = result.first;
QLineSeries *qline = new QLineSeries;
qline->setName("Trapezi");
for (auto e : result.second) *qline << QPointF(e.first, e.second);
chart->addSeries(qline);
}// graphTrapezoidal
void NumericalIntegration::graphSimpson() {
NIResult result = NIMethods::simpson(expression, from, to, resolution);
simpsonOut = result.first;
}// graphSimpson
QChart* NumericalIntegration::getChart() {
chart->createDefaultAxes();
chart->setTitle(QString::fromStdString(expression_string));
return chart;
}// getChart
void NumericalIntegration::setExpression(std::string in) {
expression_string = in;
}// setExpression
void NumericalIntegration::setInterval(double from, double to) {
this->from = from;
this->to = to;
}// setInterval
void NumericalIntegration::setResolution(unsigned int res){
resolution = res;
}// setResolution
void NumericalIntegration::setGResolution(int gres){
gresolution = gres;
}// setGResolution
void NumericalIntegration::buildExpression() {
delta = (to-from)/resolution;
gdelta = (to-from)/gresolution;
expression = new Expression(expression_string);
}// buildExpression
std::string NumericalIntegration::getExpression(){
return expression_string;
}// getExpression
double NumericalIntegration::getFrom(){
return from;
}// getFrom
double NumericalIntegration::getTo(){
return to;
}// getTo
double NumericalIntegration::getRectangleOut(){
return rectangleOut;
}// getRectangleOut
double NumericalIntegration::getTrapezoidalOut(){
return trapezoidalOut;
}// getTrapezoidalOut
double NumericalIntegration::getSimpsonOut(){
return simpsonOut;
}// getSimpsonOut