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
|
#include <iostream>
#include "include/praktable.hpp"
using table = prak::table<f64>;
using f64p = prak::pvalue<f64>;
using f64v = std::vector<f64>;
using vecarg = const std::vector<f64> &;
using argvec = const std::vector<f64> &;
void ex1(std::string file) {
table t(file);
f64p F1 = {0.0215, 0.0005}, D = {0.0061, 0.0001}, k = {0.91, 0.01};
f64 sgm = (D.err / D.val) * (D.err / D.val) + (k.err / k.val) * (k.err / k.val);
f64 F_err = std::sqrt(2.0) * F1.err;
t .apply([&F1](vecarg a){ return a[0] - F1.val;}, {"F2"}, "F")
.apply([&](vecarg a){ return a[0] / (2 * k.val * prak::PI * D.val);}, {"F"}, "s")
.apply([&](vecarg a){ return a[0] * std::sqrt(F_err * F_err / (a[1] * a[1]) + sgm);}, {"F", "s"}, "ss")
.write_plot("s(T).plot", "T", "s", "ss")
.add_columns({"q", "sq", "U", "sU"});
auto [A, B] = t.least_squares_linear("T", "s", std::make_optional("ss"), std::nullopt);
t .apply([&A](vecarg a){ return -a[0] * A.val;}, {"T"}, "q")
.apply([&A](vecarg a){ return a[0] * A.err;}, {"T"}, "sq")
.apply_function(prak::sum<f64>, {"s", "q"}, {"ss", "sq"}, "U", "sU")
.write_plot("q(T).plot", "T", "q", "sq")
.write_plot("U(T).plot", "T", "U", "sU")
.print();
auto [qA, qB] = t.least_squares_linear("T", "q", "sq", std::nullopt);
auto [UA, UB] = t.least_squares_linear("T", "U", "sU", std::nullopt);
std::cout
<< "s(T)" << A << "x+" << B << std::endl
<< "q(T)" << qA << "x+" << qB << std::endl
<< "U(T)" << UA << "x+" << UB << std::endl;
}
void ex2(std::string file) {
table t(file);
const char* strs = "1234";
std::string x = "x";
std::string f = "f";
std::string l = "f(x)";
for (int i = 0; i < 4; ++i) {
table _t({x, f}, {t.begin(x + strs[i]), t.begin(f + strs[i])}, t.find_index(x + strs[i], 0));
_t.write_plot(l + strs[i] + ".plot", "x", "f", std::nullopt).print();
}
}
int main() {
ex1("data");
ex2("data2");
return 0;
}
|