#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);}, {"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, {"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; }