-
Notifications
You must be signed in to change notification settings - Fork 0
/
reggen.h
99 lines (94 loc) · 3.23 KB
/
reggen.h
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
#pragma once
#include "dyncmatx.h"
#include "polyn.h"
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
template <class T> class reggen{
private:
dyncmatx<T> X_TAB; // X
dyncmatx<T> Y_TAB; // Y
dyncmatx<T> results; // results
dyncmatx<T> rel_errors; //errores
int prec = 5; // precision
void init(){
vector<T> ones(X_TAB.r_len(),T(1.0));
X_TAB.insert_c(ones,0);
}
void is_polynom(const unsigned int& grad){
dyncmatx<T> X_MONO = X_TAB;
dyncmatx<T> X_INS = X_MONO;
for(int i = 0; i != grad - 1;i++){
X_INS = X_INS % X_MONO;
X_TAB.add_c_dyn_fixed(X_INS);
}
}
void solve(){
results = inv(trans(X_TAB)*X_TAB) * (trans(X_TAB)*Y_TAB);
rel_errors = Y_TAB - X_TAB * results;
}
void reporte(){
cout << "Valores:" << endl;
results.show_dyn(prec);
cout << "Errores:" << endl;
rel_errors.show_dyn(prec);
}
public:
reggen(dyncmatx<T> X_TAB,dyncmatx<T> Y_TAB,const unsigned int& grad):X_TAB(X_TAB),Y_TAB(Y_TAB){
is_polynom(grad);
init();
solve();
vector<T> poly_it_res;
for(int i = 0;i != grad + 1;i++){
poly_it_res.emplace_back(results.gd_element(grad-i,0));
}
polyn<T> result_polyomial(poly_it_res);
cout << fixed << setprecision(prec) << result_polyomial << endl;
reporte();
}
reggen(vector<vector<T>> X_VR,vector<vector<T>> Y_VR,const unsigned int& grad):X_TAB(X_VR),Y_TAB(Y_VR){
is_polynom(grad);
init();
solve();
vector<T> poly_it_res;
for(int i = 0;i != grad + 1;i++){
poly_it_res.emplace_back(results.gd_element(grad-i,0));
}
polyn<T> result_polyomial(poly_it_res);
cout << fixed << setprecision(prec) << result_polyomial << endl;
reporte();
}
reggen(vector<T> X_VR_U,vector<T> Y_VR_U,const unsigned int& grad){
X_TAB = vector_to_dyn(X_VR_U);
Y_TAB = vector_to_dyn(Y_VR_U);
is_polynom(grad);
init();
solve();
vector<T> poly_it_res;
for(int i = 0;i != grad + 1;i++){
poly_it_res.emplace_back(results.gd_element(grad-i,0));
}
polyn<T> result_polyomial(poly_it_res);
cout << fixed << setprecision(prec) << result_polyomial << endl;
reporte();
}
reggen(dyncmatx<T> X_TAB,dyncmatx<T> Y_TAB):X_TAB(X_TAB),Y_TAB(Y_TAB){
init();
solve();
reporte();
}
reggen(vector<vector<T>> X_VR,vector<vector<T>> Y_VR):X_TAB(X_VR),Y_TAB(Y_VR){
init();
solve();
reporte();
}
reggen(vector<T> X_VR_U,vector<T> Y_VR_U):X_TAB(X_VR),Y_TAB(Y_VR){
X_TAB = vector_to_dyn(X_VR_U);
Y_TAB = vector_to_dyn(Y_VR_U);
init();
solve();
reporte();
}
void set_exact_results(const int& p):prec(p){}
};