-
Notifications
You must be signed in to change notification settings - Fork 0
/
integrals.cpp
149 lines (126 loc) · 3.75 KB
/
integrals.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Universidade Federal do Rio de Janeiro
* Author: Luiz Giserman
* Class: Numeric Linear Algebra
*/
#include "linearEquation.h"
#include "integrals.h"
Integral::Integral(double (*function) (vector<double>), double a, double b, int numberPoints)
{
this->function = function;
this->a = a;
this->b = b;
this->numberPoints = numberPoints;
}
double Integral::HermiteFunction (vector<double> value)
{
return this->function(value) / (exp(-value[0]));
}
double Integral::LaguerreFunction (vector<double> value)
{
return this->function(value) / (exp(-pow(value[0], 2)));
}
double Integral::Integrate()
{
vector<double> pointsHermite = HERMITE[this->numberPoints-2].first;
vector<double> weightHermite = HERMITE[this->numberPoints-2].second;
vector<double> pointsLaguerre = LAGUERRE[this->numberPoints-2].first;
vector<double> weightsLaguerre = LAGUERRE[this->numberPoints-2].second;
double hermiteSum = 0;
double laguerreSum = 0;
for (int i=0; i < this->numberPoints; i++)
{
hermiteSum += this->HermiteFunction(vector<double>{pointsHermite[i]}) * weightHermite[i];
laguerreSum += this->LaguerreFunction(vector<double>{pointsLaguerre[i]}) * weightsLaguerre[i];
}
cout << "HermiteSum : " << hermiteSum << endl;
cout << "LaguerreSum : " << laguerreSum << endl;
if (this->a == -INF)
{
if (this->b == INF)
{
return hermiteSum;
}
if (this->b >= 0)
{
this->a = 0;
return hermiteSum - laguerreSum + Integration();
}
this->a = b;
this->b = 0;
return hermiteSum - laguerreSum - Integration();
}
if(this-> b == INF)
{
if (this-> a == 0)
{
return laguerreSum;
}
if (this->a > 0)
{
this->b = a;
this->a = 0;
return laguerreSum - Integration();
}
this->b = 0;
return laguerreSum + Integration();
}
return Integration();
}
double IntegralPolinomial::Integration()
{
int i, j;
double deltaX = Utilities::GetModule(this->b - this->a) /(this->numberPoints-1);
vector<double> vb, incognitos;
BasicMatrix vandermont, matrixB;
double result = 0;
vb.reserve(this->numberPoints);
incognitos.reserve(this->numberPoints);
for (i = 1; i <= this->numberPoints; i++)
{
incognitos.push_back(this->a+(i-1)*deltaX);
vb.push_back((pow(this->b, i)-pow(this->a, i))/i);
}
vandermont.m = this->numberPoints;
vandermont.n = this->numberPoints;
vandermont.Allocate();
for(i = 0; i < (int) vandermont.m; i++)
{
for (j = 0; j < (int) vandermont.n; j++)
{
vandermont.matrix[i][j] = pow(incognitos[j], i);
}
}
matrixB.m = vb.size();
matrixB.n = 1;
matrixB.Allocate();
i = 0;
for (auto const &element: vb)
{
matrixB.matrix[i][0] = element;
i++;
}
LU vLU(vandermont, matrixB);
vLU.Solve();
for (i = 0; i < this->numberPoints; i++)
{
result += vLU.solution[i] * this->function(vector<double>{incognitos[i]});
}
return result;
}
double IntegralQuadr::Integration()
{
int i;
vector<double> pointsLegendre, weightsLegendre, incognitos;
pointsLegendre = LEGENDRE[this->numberPoints-2].first;
weightsLegendre = LEGENDRE[this->numberPoints-2].second;
double L = this->b - this->a;
double integralSum = 0;
incognitos.reserve(this->numberPoints);
for (i=0; i < this->numberPoints; i++)
{
incognitos.push_back( (this->a + this->b + pointsLegendre[i] * L) / 2);
integralSum += function(vector<double>{incognitos[i]}) * weightsLegendre[i];
}
return integralSum * L / 2;
}