diff options
author | justanothercatgirl <sotov2070@gmail.com> | 2025-03-05 20:12:26 +0300 |
---|---|---|
committer | justanothercatgirl <sotov2070@gmail.com> | 2025-03-05 20:12:26 +0300 |
commit | 620b996f2ffe5e9e426b88f57e4f46bc9af7f237 (patch) | |
tree | abb62586d4d569807ecefc007eef2316d521084c /204/main.cpp | |
parent | e10c7380486e07b277001ab3aa653b74aa990f79 (diff) |
added 204
Diffstat (limited to '204/main.cpp')
-rw-r--r-- | 204/main.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/204/main.cpp b/204/main.cpp new file mode 100644 index 0000000..64a11e2 --- /dev/null +++ b/204/main.cpp @@ -0,0 +1,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);}, {"s", "F"}, "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; +} |