aboutsummaryrefslogtreecommitdiffstats
path: root/106
diff options
context:
space:
mode:
Diffstat (limited to '106')
-rw-r--r--106/J.hpp47
-rw-r--r--106/Makefile5
-rw-r--r--106/data8
-rwxr-xr-x106/mainbin165568 -> 0 bytes
-rw-r--r--106/main.cpp143
-rw-r--r--106/plots.gp39
-rw-r--r--106/plots2.gp37
-rw-r--r--106/plots3.gp51
8 files changed, 325 insertions, 5 deletions
diff --git a/106/J.hpp b/106/J.hpp
new file mode 100644
index 0000000..a77b1d3
--- /dev/null
+++ b/106/J.hpp
@@ -0,0 +1,47 @@
+#pragma once
+#include "prakcommon.hpp"
+#include <array>
+
+inline constexpr const f64 PI = 3.141592657; // ;)
+
+inline constexpr const f64 rho_stl = 7800; // g/dm^3 (dm = decimeter)
+// delta d1 d2 d3 d4_1_ d1_ d2_ d3_ delta_
+inline constexpr const std::array d_stl =
+ {0.0102, 0.0053, 0.0072, 0.0103, 0.0162, 0.0053, 0.0072, 0.0103, 0.0102};
+// lambd l1 l2 l3 l4_1_ l1_ l2_ l3_ lambd_
+inline constexpr const std::array l_stl =
+ {0.0024, 0.0334, 0.03515, 0.071, 0.0053, 0.033, 0.0347, 0.07345, 0.0022};
+
+inline constexpr const f64 rho_alm = 2800; // g/dm^3
+// d4_1 D1 d4_2_ D2
+inline constexpr const std::array d_alm =
+ {0.01575, 0.0806, 0.01675, 0.00555};
+// l4_1 L_ l4_2_ L
+inline constexpr const std::array l_alm =
+ {0.00635, 0.0111, 0.0053, 0.0205};
+
+
+constexpr inline f64 getJ(f64 m) {
+ f64 V1 = 0, V2 = 0;
+ f64 m1 = 0, m2 = 0;
+ f64 dm;
+ f64 J1 = 0, J2 = 0;
+ f64 D = d_alm.back() + d_alm[1];
+ for (size_t i = 0; i < d_stl.size(); ++i)
+ V1 += d_stl[i] * d_stl[i] * l_stl[i];
+ for (size_t i = 0; i < d_alm.size() - 1; ++i)
+ V2 += d_alm[i] * d_alm[i] * l_alm[i];
+
+ m1 = PI * V1 * rho_stl / 4;
+ m2 = PI * rho_alm * (V2 + (D*D - d_alm[1]*d_alm[1]) * l_alm.back()) / 4;
+ dm = m - m1 - m2;
+ for (size_t i = 0; i < d_stl.size(); ++i)
+ J1 += d_stl[i] * d_stl[i];
+ J1 *= m1/8;
+
+ for (size_t i = 0; i < d_alm.size(); ++i)
+ J2 += d_alm[i] * d_alm[i];
+ J2 += D*D + d_alm[1]*d_alm[1];
+ J2 *= m2/8;
+ return J1+J2;
+}
diff --git a/106/Makefile b/106/Makefile
index c3dda94..610abc1 100644
--- a/106/Makefile
+++ b/106/Makefile
@@ -3,6 +3,11 @@ CFLAGS = -std=c++2c -mavx -Iinclude -ggdb
.PHONY: all run_main clean gnuplot
+all: gnuplot
+
+gnuplot: run_main plots.gp
+ gnuplot plots2.gp
+
run_main: main
./main
diff --git a/106/data b/106/data
new file mode 100644
index 0000000..9d985d2
--- /dev/null
+++ b/106/data
@@ -0,0 +1,8 @@
+N1 N2 t1 t2 t3 h1 h2 h3 2T1 2T2 2T3
+0 1 2.616 2.491 2.601 31.8 31.9 31.1 3.76 3.78 3.71
+1 2 4.722 4.698 4.715 28.2 27.9 27.8 3.77 3.78 3.73
+2 3 4.511 4.488 4.467 25.1 24.3 25.0 3.73 3.87 3.73
+3 4 4.301 4.284 4.216 22.7 21.9 22.1 3.76 3.75 3.75
+4 5 4.030 3.972 4.027 19.7 19.6 20.1 3.74 3.75 3.75
+5 6 3.819 3.793 3.796 18.0 18.0 18.3 3.73 3.74 3.76
+6 7 3.669 3.619 3.629 15.9 16.3 16.2 3.74 3.74 3.77
diff --git a/106/main b/106/main
deleted file mode 100755
index 5b56496..0000000
--- a/106/main
+++ /dev/null
Binary files differ
diff --git a/106/main.cpp b/106/main.cpp
index c83e5b5..e4c619e 100644
--- a/106/main.cpp
+++ b/106/main.cpp
@@ -1,13 +1,146 @@
#include "include/praktable.hpp"
-using table = prak::table<double>;
+using table = prak::table<f64>;
+using vecarg = const std::vector<f64> &;
+using f64v = std::vector<f64>;
+using f64p = prak::pvalue<f64>;
-void ex1(void) {
- table t;
- t.print();
+table prepare(std::string f) {
+ return table(f)
+ .add_column("t", {})
+ .add_column("st", {})
+ .add_column("h", {})
+ .add_column("sh", {})
+ .add_column("2T", {})
+ .add_column("s2T", {})
+ .apply(prak::avg<f64>, {"t1", "t2", "t3"}, "t")
+ .apply(prak::avg<f64>, {"h1", "h2", "h3"}, "h")
+ .apply(prak::avg<f64>, {"2T1", "2T2", "2T3"}, "2T")
+ .apply([] (vecarg a) -> f64 { return std::sqrt(std::pow(prak::stddev<f64>(a), 2) + 0.001*0.001); }, {"t1", "t2", "t3"}, "st")
+ .apply([] (vecarg a) -> f64 { return std::sqrt(std::pow(prak::stddev<f64>(a), 2) + 0.100*0.100); }, {"h1", "h2", "h3"}, "sh")
+ .apply([] (vecarg a) -> f64 { return std::sqrt(std::pow(prak::stddev<f64>(a), 2) + 0.050*0.050); }, {"2T1", "2T2", "2T3"},"s2T")
+ .delete_cols({"t1", "t2", "t3", "h1", "h2", "h3", "2T1", "2T2", "2T3"});
+}
+
+// ex1
+f64 a_ht(vecarg a) { return 8 * a[0]/100 / std::pow(a[1], 2); }
+f64 v_ht(vecarg a) { return 4 * a[0] / 100 / a[1]; }
+// ex2
+f64 tau_rvv(vecarg a) { return 2 * prak::PI * a[0] / (a[1] + a[2]); }
+f64 D2T_mvvr(vecarg a) { return a[0] * (a[1] + a[2]) * (a[1] + a[2]) / 4 / a[3]; }
+f64 Pcal(vecarg a) { return a[0] / a[1] + 1; }
+// ex3
+// [0] = m, [1] = r, [2] = g, [3] = a
+f64 j_exp(vecarg a) { return a[0] * a[1] * a[1] * (a[2] / a[3] - 1); }
+/* f64 getJ(f64 m) */ #include "J.hpp"
+// ex4
+f64 Wkin_mvjr(vecarg a) { return a[0] * a[1] * a[1] / 2 * (1 + a[2] / (a[0] * a[3] * a[3])); }
+f64 Wpot_mgh(vecarg a) { return a[0] * a[1] * a[2]; }
+
+table ex1(table &t) {
+ table result = table({"N", "a", "sa", "v", "sv", "K", "sK"}, t.rows, NAN);
+ result .apply_function_n(
+ a_ht,
+ {t.begin("h"), t.begin("t")},
+ {t.begin("sh"), t.begin("st")},
+ t.rows, "a", "sa"
+ ).apply_function_n(
+ v_ht,
+ {t.begin("h"), t.begin("t")},
+ {t.begin("sh"), t.begin("st")},
+ t.rows, "v", "sv"
+ ).apply_function_n(
+ [](vecarg a){ return a[0] / a[1]; },
+ {t.begin("h") + 1, t.begin("h")},
+ {t.begin("sh") + 1, t.begin("sh")},
+ t.rows - 1, "K", "sK");
+ result["a", 0] *= 0.25;
+ result["sa", 0] *= 0.25;
+ result["v", 0] *= 0.5;
+ result["sv", 0] *= 0.5;
+ for (size_t i = 0; i < result.rows; ++i)
+ result["N", i] = i+1;
+
+ std::cout << "Предупреждение: Колонки K, sK НАДО сдвинуть на 1 позицию вниз в тетради!\n" << result << std::endl;
+ std::cout << "среднее ускорение = " << result.col_avg("a") << std::endl;
+ result.write_plot("ex1_v.plot", "N", "v", "sv");
+ return result;
+}
+
+void ex2(table &t, table &e1) {
+ table result({"N", "tau", "stau", "D2Tmax", "sD2Tmax", "P_cal", "P_exp", "mg"}, e1.rows - 1, NAN);
+ e1.add_column("r", std::vector(e1.rows, 0.0036));
+ e1.add_column("sr", std::vector(e1.rows, 0.00005));
+ e1.add_column("m", std::vector(e1.rows, 0.385));
+ e1.add_column("sm", std::vector(e1.rows, 0.004));
+ result.fill_column("mg", 3.78);
+ result .apply_function_n(tau_rvv,
+ {e1.begin("r"), e1.begin("v"), e1.begin("v")+1},
+ {e1.begin("sr"), e1.begin("sv"), e1.begin("sv")+1},
+ e1.rows - 1, "tau", "stau"
+ ).apply_function_n(D2T_mvvr,
+ {e1.begin("m"), e1.begin("v"), e1.begin("v")+1, e1.begin("r")},
+ {e1.begin("sm"), e1.begin("sv"), e1.begin("sv")+1, e1.begin("sr")},
+ e1.rows - 1, "D2Tmax", "sD2Tmax"
+ ).apply(
+ Pcal, {"D2Tmax", "mg"}, "P_cal"
+ );
+ for (size_t i = 0; i < result.rows; ++i)
+ result["N", i] = i+1;
+ result.write_plot("ex2_t.plot", "N", "tau", "stau");
+ result.write_plot("ex2_T.plot", "N", "D2Tmax", "sD2Tmax");
+ std::cout << result << std::endl;
+}
+
+f64p ex3(table &ex1) {
+ f64p g = {9.81, 0.01};
+ f64p a = {ex1.col_avg("a"), ex1.col_stddev("a")};
+ f64p r = {ex1.col_avg("r"), ex1.col_avg("sr")};
+ f64p m = {0.385, 0.004};
+ std::vector args = {m.val, r.val, g.val, a.val};
+ std::vector sgms = {m.err, r.err, g.err, a.err};
+ f64p J_exp = {j_exp(args), prak::sigma<f64>(j_exp, args, sgms)};
+ f64 J_cal = getJ(m.val);
+ std::cout << "Experimental J = " << J_exp << "\nCalculated J = " << J_cal << std::endl;
+ return J_exp;
+}
+
+void ex4(table &t, table &e1, f64p &J) {
+ table res({"N", "W_kin", "sW_kin", "W_pot", "sW_pot", "sumW", "dW", "dW(%)"}, e1.rows, NAN);
+ e1.add_column("J", std::vector(e1.rows, J.val));
+ e1.add_column("g", std::vector(e1.rows, 9.81));
+ e1.add_column("sJ", std::vector(e1.rows, J.err));
+ e1.add_column("sg", std::vector(e1.rows, 0.01));
+ t.multiply_column("h", 0.01).multiply_column("sh", 0.01);
+
+ for (size_t i = 0; i < res.rows; ++i)
+ res["N", i] = i+1;
+
+
+ res.apply_function_n(Wkin_mvjr,
+ {e1.begin("m"), e1.begin("v"), e1.begin("J"), e1.begin("r")},
+ {e1.begin("sm"), e1.begin("sv"), e1.begin("sJ"), e1.begin("sr")},
+ e1.rows, "W_kin", "sW_kin"
+ ).apply_function_n(Wpot_mgh,
+ {e1.begin("m"), e1.begin("g"), t.begin("h")},
+ {e1.begin("sm"), e1.begin("sg"), t.begin("sh")},
+ e1.rows, "W_pot", "sW_pot"
+ ).apply([](vecarg a){return std::abs(a[0]-a[1]);}, {"W_kin", "W_pot"}, "dW")
+ .apply([](vecarg a){return std::abs(a[0]-a[1])/a[0]*100;}, {"W_kin", "W_pot"}, "dW(%)")
+ .apply([](vecarg a){return (a[0]+a[1])/2;}, {"W_kin", "W_pot"}, "sumW");
+ res.write_plot("ex4_WK.plot", "N", "W_kin", "sW_kin");
+ res.write_plot("ex4_WP.plot", "N", "W_pot", "sW_pot");
+ res.write_plot("ex4_Wfull.plot", "N", "sumW", std::nullopt);
+
+ std::cout << res;
}
int main() {
- ex1();
+ table t = prepare("data");
+ t.print();
+ table e1 = ex1(t);
+ ex2(t, e1);
+ f64p J = ex3(e1);
+ ex4(t, e1, J);
return 0;
}
diff --git a/106/plots.gp b/106/plots.gp
new file mode 100644
index 0000000..aecb7d3
--- /dev/null
+++ b/106/plots.gp
@@ -0,0 +1,39 @@
+# Set common properties
+set terminal pngcairo size 600,800 enhanced
+set style line 1 lw 2 pt 7 lc rgb "blue" # Line style 1
+set style line 2 lw 2 pt 5 lc rgb "red" # Line style 2
+set style line 3 lw 2 pt 9 lc rgb "green" # Line style 3
+
+# Plot 1: ex1_v.plot with yerrorbars and lines
+set output "ex1_velocity.png"
+set xlabel "N, количество"
+set ylabel "Скорость (м/с)"
+set key top left
+plot "ex1_v.plot" using 1:2:3 with yerrorbars ls 1 title "Скорость", \
+ "ex1_v.plot" using 1:2 with lines ls 1 notitle
+
+# Plot 2: ex2_t.plot and ex2_T.plot with two Y axes and lines
+set output "ex2_time_force.png"
+set xlabel "N, количество"
+set ylabel "Время (с)"
+set y2label "Сила (Н)"
+set y2tics
+set ytics nomirror
+set key top left
+plot "ex2_t.plot" using 1:2:3 with yerrorbars ls 1 title "Время", \
+ "ex2_t.plot" using 1:2 with lines ls 1 notitle, \
+ "ex2_T.plot" using 1:2:3 axes x1y2 with yerrorbars ls 2 title "Сила", \
+ "ex2_T.plot" using 1:2 axes x1y2 with lines ls 2 notitle
+
+# Plot 3: ex4_WK.plot, ex4_WP.plot (yerrorbars and lines) and ex4_Wfull.plot (lines only)
+set output "ex4_energy.png"
+set xlabel "N, количество"
+set ylabel "Энергия (Дж)"
+set key top left
+plot "ex4_WK.plot" using 1:2:3 with yerrorbars ls 1 title "Энергия Wk", \
+ "ex4_WK.plot" using 1:2 with lines ls 1 notitle, \
+ "ex4_WP.plot" using 1:2:3 with yerrorbars ls 2 title "Энергия Wp", \
+ "ex4_WP.plot" using 1:2 with lines ls 2 notitle, \
+ "ex4_Wfull.plot" using 1:2 with lines ls 3 title "Полная энергия"
+
+
diff --git a/106/plots2.gp b/106/plots2.gp
new file mode 100644
index 0000000..5dbdc9e
--- /dev/null
+++ b/106/plots2.gp
@@ -0,0 +1,37 @@
+
+# Common settings
+set terminal pngcairo size 1000, 800 enhanced
+set grid
+set datafile separator whitespace
+set key top left
+set xlabel "N, количество" font ",14"
+
+# 1. Plot ex1_v.plot
+set output "plot1_velocity.png"
+set ylabel "Скорость (м/с)" font ",14"
+plot \
+ "ex1_v.plot" using 1:2:3 with yerrorbars linecolor rgb "blue" pointtype 7 title "Скорость", \
+ "ex1_v.plot" using 1:2 smooth mcspline with lines linetype 2 linecolor rgb "blue" title ""
+
+# 2. Plot ex2_t.plot and ex2_T.plot
+set output "plot2_time_force.png"
+set ylabel "t (с)" font ",14"
+set y2label "Сила (Н)" font ",14"
+set y2tics
+set ytics nomirror
+plot \
+ "ex2_t.plot" using 1:2:3 with yerrorbars linecolor rgb "red" pointtype 5 title "Время", \
+ "ex2_t.plot" using 1:2 smooth mcspline with lines linetype 2 linecolor rgb "red" title "", \
+ "ex2_T.plot" using 1:2:3 axes x1y2 with yerrorbars linecolor rgb "green" pointtype 7 title "Сила", \
+ "ex2_T.plot" using 1:2 smooth mcspline axes x1y2 with lines linetype 2 linecolor rgb "green" title ""
+
+# 3. Plot ex4_WK.plot, ex4_WP.plot, ex4_Wfull.plot
+set output "plot3_energy.png"
+set ylabel "Энергия (единицы энергии)" font ",14"
+plot \
+ "ex4_WK.plot" using 1:2:3 with yerrorbars linecolor rgb "magenta" pointtype 7 title "Wk", \
+ "ex4_WK.plot" using 1:2 smooth mcspline with lines linetype 2 linecolor rgb "magenta" title "", \
+ "ex4_WP.plot" using 1:2:3 with yerrorbars linecolor rgb "cyan" pointtype 5 title "Wp", \
+ "ex4_WP.plot" using 1:2 smooth mcspline with lines linetype 2 linecolor rgb "cyan" title "", \
+ "ex4_Wfull.plot" using 1:2 with lines linecolor rgb "black" linetype 3 linewidth 1 title "Wfull"
+
diff --git a/106/plots3.gp b/106/plots3.gp
new file mode 100644
index 0000000..c763292
--- /dev/null
+++ b/106/plots3.gp
@@ -0,0 +1,51 @@
+# Common settings
+set terminal pngcairo size 1000, 800 enhanced
+set grid
+set datafile separator whitespace
+set xlabel "N, ед." font ",14"
+
+# 1. Plot ex1_v.plot
+set output "plot1_velocity.png"
+set ylabel "v (м/с)" font ",14"
+f1(x) = a1 * x + b1
+fit f1(x) "ex1_v.plot" using 1:2 via a1, b1
+plot \
+ "ex1_v.plot" using 1:2:3 with yerrorbars linecolor rgb "blue" pointtype 7 title "v", \
+ f1(x) with lines linetype 2 linecolor rgb "blue" notitle
+
+# 2. Plot ex2_t.plot and ex2_T.plot
+set output "plot2_time_force.png"
+set ylabel "t (с)" font ",14"
+set y2label "F (Н)" font ",14"
+set y2tics
+set ytics nomirror
+f2(x) = a2 * x + b2
+fit f2(x) "ex2_t.plot" using 1:2 via a2, b2
+f3(x) = a3 * x + b3
+fit f3(x) "ex2_T.plot" using 1:2 via a3, b3
+plot \
+ "ex2_t.plot" using 1:2:3 with yerrorbars linecolor rgb "red" pointtype 5 title "t, c", \
+ f2(x) with lines linetype 2 linecolor rgb "red" notitle,\
+ "ex2_T.plot" using 1:2:3 axes x1y2 with yerrorbars linecolor rgb "green" pointtype 7 title "F, Н", \
+ f3(x) axes x1y2 with lines linetype 2 linecolor rgb "green" notitle
+
+unset y2tics
+unset y2label
+# 3. Plot ex4_WK.plot, ex4_WP.plot, ex4_Wfull.plot
+set output "plot3_energy.png"
+set ylabel "Энергия (единицы энергии)" font ",14"
+f4(x) = a4 * x + b4
+fit f4(x) "ex4_WK.plot" using 1:2 via a4, b4
+f5(x) = a5 * x + b5
+fit f5(x) "ex4_WP.plot" using 1:2 via a5, b5
+f6(x) = a6 * x + b6
+fit f6(x) "ex4_Wfull.plot" using 1:2 via a6, b6
+plot \
+ "ex4_WK.plot" using 1:2:3 with yerrorbars lc rgb "red" pointtype 5 title "W_k", \
+ f4(x) with lines linetype 2 linecolor rgb "green" notitle, \
+ "ex4_WP.plot" using 1:2:3 with yerrorbars lc rgb "green" pointtype 5 title "W_p", \
+ f5(x) with lines linetype 2 linecolor rgb "blue" notitle, \
+ "ex4_Wfull.plot" using 1:2 pt 5 linecolor rgb "blue" title "W_{full}", \
+ f6(x) with lines linetype 2 linecolor rgb "red" notitle
+
+