diff options
Diffstat (limited to '101')
-rw-r--r-- | 101/Makefile | 18 | ||||
-rw-r--r-- | 101/README.md | 5 | ||||
-rw-r--r-- | 101/compile_flags.txt | 4 | ||||
-rw-r--r-- | 101/ex1 | 11 | ||||
-rw-r--r-- | 101/ex2 | 11 | ||||
-rw-r--r-- | 101/ex3 | 11 | ||||
l--------- | 101/include | 1 | ||||
-rwxr-xr-x | 101/main | bin | 0 -> 621352 bytes | |||
-rw-r--r-- | 101/main.cpp | 137 | ||||
-rw-r--r-- | 101/mass | 20 | ||||
-rw-r--r-- | 101/plots.gp | 14 |
11 files changed, 232 insertions, 0 deletions
diff --git a/101/Makefile b/101/Makefile new file mode 100644 index 0000000..eb309ff --- /dev/null +++ b/101/Makefile @@ -0,0 +1,18 @@ + +CFLAGS = -std=c++2c -mavx -Iinclude -ggdb + +.PHONY: all run_main clean gnuplot + +run: gnuplot + +gnuplot: plots.gp run_main + gnuplot $< + +run_main: main + ./main + +main: main.cpp include/* + $(CXX) -o $@ $< $(CFLAGS) + +clean: + rm -fr main *.png *.plot diff --git a/101/README.md b/101/README.md new file mode 100644 index 0000000..96fd716 --- /dev/null +++ b/101/README.md @@ -0,0 +1,5 @@ +<!-- Шаблон для прака --> +<!-- файлы, заканчивающиеся на .plot считаются генерируемыми и удаляются через make clean --> +# Обработка <> прака + + diff --git a/101/compile_flags.txt b/101/compile_flags.txt new file mode 100644 index 0000000..34ae930 --- /dev/null +++ b/101/compile_flags.txt @@ -0,0 +1,4 @@ +-Iinclude +-std=c++2c +-mavx2 + @@ -0,0 +1,11 @@ +N a1 a2 a3 a sa acal sacal +1 0.13346 0.13171 0.132942 ? ? ? ? +2 0.282912 0.282706 0.28394 ? ? ? ? +3 0.429228 0.428942 0.429562 ? ? ? ? +4 0.569562 0.567884 0.56956 ? ? ? ? +5 0.7058 0.704906 0.70637 ? ? ? ? +6 0.838736 0.821824 0.84288 ? ? ? ? +7 0.969494 0.967614 0.9688 ? ? ? ? +8 1.095644 1.094602 1.094976 ? ? ? ? +9 1.217494 1.21835 1.219444 ? ? ? ? +10 1.33011 1.324222 1.335216 ? ? ? ? @@ -0,0 +1,11 @@ +N m1 m2 a1 a2 a3 a +1 ? ? 0.133954 0.132362 0.135396 ? +2 ? ? 0.125120 0.129666 0.129296 ? +3 ? ? 0.121898 0.123508 0.122264 ? +4 ? ? 0.119830 0.119476 0.116626 ? +5 ? ? 0.110080 0.111944 0.112238 ? +6 ? ? 0.108780 0.111320 0.110016 ? +7 ? ? 0.108712 0.106222 0.107966 ? +8 ? ? 0.104368 0.105308 0.105832 ? +9 ? ? 0.099952 0.102050 0.101092 ? +10 ? ? 0.100834 0.100822 0.101342 ? @@ -0,0 +1,11 @@ +N m1 m2 dm a1 a2 a3 a +1 ? ? ? 0.101242 0.100606 0.100698 ? +2 ? ? ? 0.324394 0.343446 0.345500 ? +3 ? ? ? 0.587238 0.587220 0.564608 ? +4 ? ? ? 0.828416 0.830074 0.815484 ? +5 ? ? ? 1.063504 1.071230 1.070982 ? +6 ? ? ? 1.305656 1.305208 1.307460 ? +7 ? ? ? 1.550900 1.548880 1.550336 ? +8 ? ? ? 1.794500 1.792756 1.788620 ? +9 ? ? ? 2.032050 2.032032 2.034266 ? +10 ? ? ? 2.269558 2.272532 2.273842 ? diff --git a/101/include b/101/include new file mode 120000 index 0000000..2225752 --- /dev/null +++ b/101/include @@ -0,0 +1 @@ +../libprakpp/include/
\ No newline at end of file diff --git a/101/main b/101/main Binary files differnew file mode 100755 index 0000000..cb77291 --- /dev/null +++ b/101/main diff --git a/101/main.cpp b/101/main.cpp new file mode 100644 index 0000000..54d956d --- /dev/null +++ b/101/main.cpp @@ -0,0 +1,137 @@ +#include <iostream> + +#include "include/praktable.hpp" + +using table = prak::table<f64>; +using vecarg = const std::vector<f64> &; +using f64v = std::vector<f64>; +using f64p = prak::pvalue<f64>; + +const f64 g = 9.81571; // moscow local acceleration +const f64 m_0 = 113.63 / 1000.0; +const f64 m_s = 0.01 / 1000.0; + +f64p avg_mass(void) { + std::ifstream f("mass"); + f64 acc = 0; + u32 cnt = 0; + for (f64 tmp; f >> tmp; acc += tmp, ++cnt); + f64 avg = acc / cnt; + f.clear(); + f.seekg(0, std::ios::beg); + f64 stddev_acc = 0; + for (f64 tmp; f >> tmp; stddev_acc += (tmp-avg)*(tmp-avg)); + return {.val = avg / 1000.0, .err = std::sqrt(stddev_acc / cnt / (cnt - 1)) / 1000.0}; +} + +// args[0] = dm +// args[1] = m +f64 acal(vecarg args) { + return g * args[0] / args[1]; +} + +f64 get_g(vecarg args) { + f64 C = args[0], + m_bl = args[1], + m = args[2], + m0 = args[3], + a = args[4]; + return C * (a*m_bl + m + m0); +} + +f64 get_M(vecarg args) { + f64 D = args[0], + m_bl = args[1], + m = args[2], + m0 = args[3], + a = args[4], + R = args[5]; + return D * (a*m_bl + m + m0) * R; +} + +void ex1(f64p m) { + table t("ex1"); + t .apply(prak::avg<f64>, {"a1", "a2", "a3"}, "a") + .apply(prak::stddev<f64>, {"a1", "a2", "a3"}, "sa") + .apply([m](vecarg arg) -> f64 { + return acal({arg[0] * m.val, (m_0 + arg[0]*m.val)}); + }, {"N"}, "acal") + .apply([m](vecarg arg) -> f64 { + f64v args = {arg[0] * m.val, m_0 + arg[0]*m.val}; + f64v sigmas = {m.err * arg[0], m_s}; + return prak::sigma<f64>(acal, args, sigmas); + }, {"N"}, "sacal"); + t.write_plot("ex1_exp.plot", "N", "a", "sa"); + t.write_plot("ex1_calc.plot", "N", "acal", "sacal"); + std::cout << "Упражнение 1: " << t << std::endl; +} + +void ex2(f64p m) { + table in("ex2"); + in .apply([m] (vecarg a) { return m.val * (a[0] - 1); }, {"N"}, "m1") + .apply([m] (vecarg a) { return m.val * a[0]; }, {"N"}, "m2") + .apply(prak::avg<f64>, {"a1", "a2", "a3"}, "a"); + table out({"N", "M", "1/M", "a_exp", "a_cal", "da(%)"}, in.rows, NAN); + { + int N = 0; + for (auto it = out.begin("N"); it != out.end("N"); ++it) *it = ++N; + for (size_t i = 0; i < in.rows; ++i) out["a_exp", i] = in["a", i]; + out .apply([m] (vecarg a) { return (2*a[0] - 1)*m.val + m_0; }, {"N"}, "M") + .apply([m] (vecarg a) { return acal({m.val, a[0]}); }, {"M"}, "a_cal") + .apply([ ] (vecarg a) { return std::abs(a[0]-a[1])/a[0]*100; }, {"a_cal", "a_exp"}, "da(%)") + .apply([ ] (vecarg a) { return 1.0/a[0]; }, {"M"}, "1/M"); + } + std::cout << "Таблица 3: " << in << "\nТаблица 4: " << out << std::endl; + + out.write_plot("ex2_exp.plot", "1/M", "a_exp", std::nullopt); + out.write_plot("ex2_cal.plot", "1/M", "a_cal", std::nullopt); + out.write_plot("ex2_dev.plot", "1/M", "da(%)", std::nullopt); +} + +void ex3(f64p m) { + table in("ex3"); + in .apply([m] (vecarg a) { return (10 - a[0]) * m.val; }, {"N"}, "m1") + .apply([m] (vecarg a) { return ( 9 + a[0]) * m.val; }, {"N"}, "m2") + .apply([m] (vecarg a) { return (2 * a[0] - 1) * m.val; }, {"N"}, "dm") + .apply(prak::avg<f64>, {"a1", "a2", "a3"}, "a"); + in.add_column("sa", {}); + in.apply(prak::stddev<f64>, {"a1", "a2", "a3"}, "sa"); + table out({"N", "dm", "M", "1/M", "a_exp", "a_cal", "da(%)"}, in.rows, NAN); + { + int N = 0; + for (auto it = out.begin("N"); it != out.end("N"); ++it) *it = ++N; + for (size_t i = 0; i < in.rows; ++i) out["a_exp", i] = in["a", i]; + out.fill_column("M", 19 * m.val + m_0); + out .apply([m] (vecarg a) { return (2 * a[0] - 1) * m.val; }, {"N"}, "dm") + .apply([ ] (vecarg a) { return acal({a[0], a[1]}); }, {"dm", "M"}, "a_cal") + .apply([ ] (vecarg a) { return std::abs(a[0]-a[1])/a[0]*100; }, {"a_cal", "a_exp"}, "da(%)") + .apply([ ] (vecarg a) { return 1.0/a[0]; }, {"M"}, "1/M"); + } + std::cout << "Таблица 5: " << in << "\nТаблица 6: " << out << std::endl; + out.write_plot("ex3_exp.plot", "dm", "a_exp", std::nullopt); + out.write_plot("ex3_cal.plot", "dm", "a_cal", std::nullopt); + out.write_plot("ex3_dev.plot", "dm", "da(%)", std::nullopt); + auto [C, D] = out.least_squares_linear("dm", "a_exp", std::nullopt, in.col_avg("sa")); + f64p g, M; + f64v g_args = {C.val, 0.0175, m.val * 19, m_0, 0.3}, + g_sigmas = {C.err, 0.0005, m.err * 19, m_s, 0.1}; + g.val = get_g(g_args); + g.err = prak::sigma<f64>(get_g, g_args, g_sigmas); + f64v M_args = {D.val, 0.0175, m.val * 19, m_0, 0.3, 0.025}, + M_sigmas = {D.err, 0.0005, m.err * 19, m_s, 0.0, 0.001}; + M.val = get_M(M_args); + M.err = prak::sigma<f64>(get_M, M_args, M_sigmas); + std::cout << "Результаты регрессии:\n\tC = " << C << "\tD = " << D << '\n' + << "Полученное значение g:\n\tg = " << g << '\n' + << "Полученное значение M:\n\tM = " << M << std::endl; +} + +int main() { + f64p m = avg_mass(); + std::cout << "Средняя масса = " << m << std::endl; + ex1(m); + ex2(m); + ex3(m); + + return 0; +} diff --git a/101/mass b/101/mass new file mode 100644 index 0000000..2e48479 --- /dev/null +++ b/101/mass @@ -0,0 +1,20 @@ +1.88 +1.87 +1.87 +1.85 +1.86 +1.88 +1.88 +1.88 +1.88 +1.87 +1.87 +1.88 +1.88 +1.89 +1.89 +1.89 +1.86 +1.86 +1.86 +1.86 diff --git a/101/plots.gp b/101/plots.gp new file mode 100644 index 0000000..702408a --- /dev/null +++ b/101/plots.gp @@ -0,0 +1,14 @@ +set term pngcairo size 1000, 800 +set tmargin at screen 0.95 + +f1(x) = a1*x+b1 +fit f1(x) '.plot' using 1:2:3 yerr via a1, b1 + +set output '' +set label "" at graph 0.5, graph 1.025 center +set xlabel "" +set ylabel "" + +plot '.plot' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2, \ + f1(x) title "" lc rgb "red", \ + |