From 620b996f2ffe5e9e426b88f57e4f46bc9af7f237 Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Wed, 5 Mar 2025 20:12:26 +0300 Subject: added 204 --- 204/main.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 204/main.cpp (limited to '204/main.cpp') 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 + +#include "include/praktable.hpp" + +using table = prak::table; +using f64p = prak::pvalue; +using f64v = std::vector; +using vecarg = const std::vector &; +using argvec = const std::vector &; + +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, {"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; +} -- cgit v1.2.3-70-g09d2