diff options
Diffstat (limited to 'vtek7')
-rw-r--r-- | vtek7/Makefile | 18 | ||||
-rw-r--r-- | vtek7/README.md | 5 | ||||
-rw-r--r-- | vtek7/compile_flags.txt | 4 | ||||
-rw-r--r-- | vtek7/data | 0 | ||||
-rw-r--r-- | vtek7/data1 | 6 | ||||
-rw-r--r-- | vtek7/data2 | 6 | ||||
-rw-r--r-- | vtek7/data3 | 20 | ||||
-rw-r--r-- | vtek7/data4 | 6 | ||||
-rw-r--r-- | vtek7/data6 | 15 | ||||
-rw-r--r-- | vtek7/data_common | 2 | ||||
l--------- | vtek7/include | 1 | ||||
-rw-r--r-- | vtek7/main.cpp | 178 | ||||
-rw-r--r-- | vtek7/plots.gp | 124 |
13 files changed, 385 insertions, 0 deletions
diff --git a/vtek7/Makefile b/vtek7/Makefile new file mode 100644 index 0000000..224506f --- /dev/null +++ b/vtek7/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 $< &>/dev/null + +run_main: main + ./main + +main: main.cpp include/* + $(CXX) -o $@ $< $(CFLAGS) + +clean: + rm -fr main *.png *.plot diff --git a/vtek7/README.md b/vtek7/README.md new file mode 100644 index 0000000..96fd716 --- /dev/null +++ b/vtek7/README.md @@ -0,0 +1,5 @@ +<!-- Шаблон для прака --> +<!-- файлы, заканчивающиеся на .plot считаются генерируемыми и удаляются через make clean --> +# Обработка <> прака + + diff --git a/vtek7/compile_flags.txt b/vtek7/compile_flags.txt new file mode 100644 index 0000000..34ae930 --- /dev/null +++ b/vtek7/compile_flags.txt @@ -0,0 +1,4 @@ +-Iinclude +-std=c++2c +-mavx2 + diff --git a/vtek7/data b/vtek7/data new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vtek7/data diff --git a/vtek7/data1 b/vtek7/data1 new file mode 100644 index 0000000..c035231 --- /dev/null +++ b/vtek7/data1 @@ -0,0 +1,6 @@ +x L E1 E2 E3 sLux sE sSum E 1/L^2 +? 10 2974 2934 3030 ? ? ? ? ? +? 15 1261 1197 1246 ? ? ? ? ? +? 20 558 550 555 ? ? ? ? ? +? 25 430 427 456 ? ? ? ? ? +? 30 245.7 246 247.5 ? ? ? ? ? diff --git a/vtek7/data2 b/vtek7/data2 new file mode 100644 index 0000000..5f92a6e --- /dev/null +++ b/vtek7/data2 @@ -0,0 +1,6 @@ +L U_fd0 U_fd sU I_fd0 I_fd sI E +10 0.2466 ? ? 12.8 ? ? ? +15 0.2086 ? ? 4.6 ? ? ? +20 0.1808 ? ? 2.2 ? ? ? +25 0.1574 ? ? 1.3 ? ? ? +30 0.1393 ? ? 0.9 ? ? ? diff --git a/vtek7/data3 b/vtek7/data3 new file mode 100644 index 0000000..4046606 --- /dev/null +++ b/vtek7/data3 @@ -0,0 +1,20 @@ +U U1 sU1 I1 sI1 U2 sU2 I2 sI2 +-10 -9.993 ? -2.1 ? -10 ? 1.2 ? +-8 -7.960 ? -1.9 ? -7.968 ? 1.0 ? +-6 -5.959 ? -1.7 ? -5.968 ? 0.8 ? +-4 -4.004 ? -1.5 ? -4.010 ? 0.6 ? +-2 -1.977 ? -1.2 ? -1.9844 ? 0.3 ? +-1 -0.9977 ? -1.1 ? -1.0040 ? 0.2 ? +-0 -0.0257 ? -0.9 ? -0.0345 ? 0 ? +0 0.0420 ? -0.9 ? 0.0350 ? 0 ? +0.2 0.2064 ? 1.1 ? 0.2012 ? 1.7 ? +0.4 0.2822 ? 14.9 ? 0.2806 ? 15.1 ? +0.6 0.3135 ? 41.8 ? 0.3145 ? 41.9 ? +0.8 0.3281 ? 62.1 ? 0.3277 ? 62.1 ? +1 0.3385 ? 84.9 ? 0.3382 ? 84.9 ? +2 0.3689 ? 199.9 ? 0.3685 ? 199.9 ? +3 0.3935 ? 370 ? 0.3934 ? 370 ? +4 0.4082 ? 514 ? 0.4082 ? 514 ? +5 0.4198 ? 652 ? 0.4198 ? 652 ? +10 0.4622 ? 1366 ? 0.4622 ? 1366 ? + diff --git a/vtek7/data4 b/vtek7/data4 new file mode 100644 index 0000000..cdf8ba9 --- /dev/null +++ b/vtek7/data4 @@ -0,0 +1,6 @@ +L U0 sU I0(1) sI(1) I0(2) sI(2) E +10 2.1855 ? 700 ? 700 ? ? +15 2.0260 ? 232 ? 233 ? ? +20 1.8340 ? 111.1 ? 124.49 ? ? +25 1.6666 ? 66.6 ? 75.40 ? ? +30 1.1503 ? 45.3 ? 51.33 ? ? diff --git a/vtek7/data6 b/vtek7/data6 new file mode 100644 index 0000000..c8473d4 --- /dev/null +++ b/vtek7/data6 @@ -0,0 +1,15 @@ +N R U sU I sI W sW Nu sNu +1 20 0.008 ? 735 ? ? ? ? ? +2 50 0.017 ? 736 ? ? ? ? ? +3 1300 0.463 ? 679 ? ? ? ? ? +4 3130 1.492 ? 487 ? ? ? ? ? +5 5040 1.703 ? 345 ? ? ? ? ? +6 10020 1.903 ? 195.41 ? ? ? ? ? +7 15150 1.984 ? 135.13 ? ? ? ? ? +8 25000 2.04 ? 105.98 ? ? ? ? ? +9 29730 2.05 ? 85.00 ? ? ? ? ? +10 29800 2.08 ? 72.26 ? ? ? ? ? +11 35100 2.07 ? 62.09 ? ? ? ? ? +12 40000 2.08 ? 54.91 ? ? ? ? ? +13 45100 2.02 ? 49.13 ? ? ? ? ? +14 48300 2.03 ? 46.05 ? ? ? ? ? diff --git a/vtek7/data_common b/vtek7/data_common new file mode 100644 index 0000000..2a51b8c --- /dev/null +++ b/vtek7/data_common @@ -0,0 +1,2 @@ +E_amb_max E_amb_min x_max x_min x_true x_true_approx E_amb sE_amb U_amb sU_amb I_amb U_amb_4 I_amb_4 +13.3 9.1 30 0 -6.9 -6 ? ? 0.0127 0.0017 0 0.674 0.00000213 diff --git a/vtek7/include b/vtek7/include new file mode 120000 index 0000000..2225752 --- /dev/null +++ b/vtek7/include @@ -0,0 +1 @@ +../libprakpp/include/
\ No newline at end of file diff --git a/vtek7/main.cpp b/vtek7/main.cpp new file mode 100644 index 0000000..b5d4318 --- /dev/null +++ b/vtek7/main.cpp @@ -0,0 +1,178 @@ +#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> &; + +table common; + +f64p get(const std::string &key, const std::string &skey) { return {common[key, 0], common[skey, 0]}; } +f64 &get(const std::string &key) { return common[key, 0]; } + +f64 lux_err(vecarg a) { + if (a[0] < 10000) return a[0] * 0.05; + return a[0] * 0.1; +} +f64 U_err_MS8040(vecarg a) { + f64 u = a[0]; + if (u < 0.2) return u * 0.0005 + 6e-5; + if (u < 2) return u * 0.0005 + 6e-4; + if (u < 20) return u * 0.0005 + 6e-3; + if (u < 200) return u * 0.0005 + 6e-2; + return u*0.0005 + 6e-1; +} +f64 I_err_MS8040(vecarg a) { + f64 i = a[0]; + if (i < 2e-4) return i * 0.0015 + 15e-8; + if (i < 2e-3) return i * 0.0015 + 15e-7; + if (i < 2e-2) return i * 0.0015 + 15e-6; + return i * 0.0015 + 15e-5; +} +f64 U_err_DT320B(vecarg a) { + f64 u = a[0]; + if (u < 2e-1) return 0.0025*u + 2e-4; + if (u < 2e0) return 0.005*u + 2e-3; + if (u < 2e1) return 0.005*u + 2e-2; + if (u < 2e2) return 0.005*u + 2e-1; + return 0.005*u + 2e0; +} +f64 I_err_DT830B(vecarg a) { + f64 i = a[0]; + if (i < 2e-4) return 0.01*i + 2e-7; + if (i < 2e-3) return 0.01*i + 2e-6; + if (i < 2e-2) return 0.01*i + 2e-5; + if (i < 2e-1) return 0.012*i + 2e-4; + return 0.02 * i + 2e-2; +} +f64 R_err_DT830B(vecarg a) { + f64 r = a[0]; + if (r < 2e2) return 0.008*r + 2e-1; + if (r < 2e3) return 0.008*r + 2e0; + if (r < 2e4) return 0.008*r + 2e1; + if (r < 2e5) return 0.008*r + 2e2; + return 0.01*r + 2e3; +} + +table ex1(std::string file) { + std::cout << "Упражнение 1:\n"; + table t(file); + f64 emacs = get("E_amb_max"), + emin = get("E_amb_min"); + f64p E_amb = {(emacs + emin)/2, (emacs-emin)/2}; + f64 x_true = get("x_true"); + get("E_amb") = E_amb.val; + get("sE_amb") = E_amb.err; + t .multiply_column("L", 1e-2) + .into_avgstddev({"E1", "E2", "E3"}, "E", "sE", false) + .apply(lux_err, {"E"}, "sLux") + .apply([x_true](vecarg a){ return a[0] + x_true; }, {"L"}, "x") + .apply([E_amb](vecarg a){ return a[0] - E_amb.val; }, {"E"}, "E") + .apply([E_amb](vecarg a){ return std::sqrt(a[0]*a[0] + E_amb.err*E_amb.err / 3); }, {"sE"}, "sE") + // Если буду подгонять погрешности, убрать ................................ ^^^ <- эту тройку + .apply(prak::hypot<f64>, {"sE", "sLux"}, "sSum") + .apply([](vecarg a){ return 1/a[0]/a[0]; }, {"L"}, "1/L^2") + .print(); + t.write_plot("ex1_EL.plot", "1/L^2", "E", "sE"); + auto [a, b] = t.least_squares_linear("1/L^2", "E", "sE", std::nullopt); + std::cout << "\nРезультаты мнк:\n\tA = " << a + << "\n\tB = " << b + << "\n E_фон = " << E_amb << std::endl; + return t; +} + +void ex2(std::string file, table &e1) { + std::cout << "Упражнение 2:\n"; + table t(file); + f64 U_amb = get("U_amb"); + f64 I_amb = get("I_amb"); + std::copy_n(e1.begin("E"), e1.rows, t.begin("E")); + t .multiply_column("L", 1e-2) + .multiply_column("I_fd0", 1e-6) + .apply([U_amb](vecarg a){ return a[0] - U_amb; }, {"U_fd0"}, "U_fd") + .apply([I_amb](vecarg a){ return a[0] - I_amb; }, {"I_fd0"}, "I_fd") + .apply(U_err_MS8040, {"U_fd"}, "sU") + .apply(I_err_MS8040, {"I_fd"}, "sI") + .write_plot("ex2_UE.plot", "E", "U_fd", "sU") + .write_plot("ex2_IE.plot", "E", "I_fd", "sI") + .print(); +} + +void ex3(std::string file) { + std::cout << "Упражнение 3:\n"; + table t(file); + t .multiply_column("I1", 1e-6) + .multiply_column("I2", 1e-6) + .apply(U_err_MS8040, {"U1"}, "sU1") + .apply(U_err_MS8040, {"U2"}, "sU2") + .apply(I_err_DT830B, {"I1"}, "sI1") + .apply(I_err_DT830B, {"I2"}, "sI2") + .write_plot_4("ex3_1.plot", "U1", "I1", "sU1", "sI1") + .write_plot_4("ex3_2.plot", "U2", "I2", "sU2", "sI2") + .print(); +} + +void ex4(std::string file, table &e1) { + std::cout << "Упражнение 4:\n"; + table t(file); + f64 U_amb = get("U_amb_4"); + f64 I_amb = get("I_amb_4"); + std::copy_n(e1.begin("E"), e1.rows, t.begin("E")); + t .multiply_column("L", 1e-2) + .multiply_column("I0(1)", 1e-6) + .multiply_column("I0(2)", 1e-6) + .add_column("U") + .add_column("I(1)") + .add_column("I(2)") + .apply([U_amb](vecarg a){ return a[0] - U_amb; }, {"U0"}, "U") + .apply([I_amb](vecarg a){ return a[0] - I_amb; }, {"I0(1)"}, "I(1)") + .apply([I_amb](vecarg a){ return a[0] - I_amb; }, {"I0(2)"}, "I(2)") + .apply(U_err_MS8040, {"U0"}, "sU") + .apply(I_err_MS8040, {"I0(1)"}, "sI(1)") + .apply(I_err_MS8040, {"I0(2)"}, "sI(2)") + .write_plot("ex4_UE.plot", "E", "U", "sU") + .write_plot("ex4_IE_1.plot", "E", "I(1)", "sI(1)") + .write_plot("ex4_IE_2.plot", "E", "I(2)", "sI(2)") + .print(); +} + +void ex6(std::string file, table &e1) { + std::cout << "Упражнение 6\n"; + table t(file); + size_t idx = e1.find_index("L", 10); + f64p a = {0.024, 0.0003}, + b = {0.038, 0.0003}; + f64p S = prak::function<f64>(prak::prod<f64>, {a, b}), + E = {e1["E", idx], e1["sE", idx]}; + f64p Ф = prak::function<f64>([](vecarg a){ return a[0] * a[1] / 683; }, {S, E}); + t .multiply_column("I", 1e-6) + .apply(U_err_DT320B, {"U"}, "sU") + .apply(I_err_MS8040, {"I"}, "sI") + .add_column("sR", 0) + .apply(R_err_DT830B, {"R"}, "sR") + .apply_with_err(prak::prod<f64>, {"U", "I"}, {"sU", "sI"}, "W", "sW") + .copy_column("W", "Nu") + .copy_column("sW", "sNu") + .multiply_column("Nu", 1/Ф.val) + .apply + ([Ф](vecarg a) { return a[0] * std::sqrt(std::pow(a[1]/a[2], 2) + std::pow(Ф.err/Ф.val, 2)); }, + {"Nu", "sW", "W"}, "sNu" + ) + .multiply_column("R", 1e-3) + .write_plot_4("ex6_UI.plot", "U", "I", "sU", "sI") + .write_plot_4("ex6_nuR.plot", "R", "Nu", "sR", "sNu") + .print(); +} + +int main() { + common = table("data_common"); + table e1 = ex1("data1"); + ex2("data2", e1); + ex3("data3"); + ex4("data4", e1); + ex6("data6", e1); + return 0; +} diff --git a/vtek7/plots.gp b/vtek7/plots.gp new file mode 100644 index 0000000..0f38281 --- /dev/null +++ b/vtek7/plots.gp @@ -0,0 +1,124 @@ +set term pngcairo size 1000, 800 + +f1(x) = a1 * x + b1 +fit f1(x) 'ex1_EL.plot' yerr via a1, b1 + +f21(x) = a21 * x + b21 +f22(x) = a22*log(x - b22) + c22 +fit f21(x) 'ex2_IE.plot' yerr via a21, b21 +fit f22(x) 'ex2_UE.plot' via a22, b22, c22 + +#f31(x) = a31*(x + c31) + exp(b31*(x + c31)) +#f32(x) = a32*(x + c32) + exp(b32*(x + c32)) +#fit f31(x) 'ex3_1.plot' xyerr via a31, b31, c31 +#fit f32(x) 'ex3_2.plot' xyerr via a32, b32, c32 + +f41(x) = a41*log(x - b41) + c41 +f42(x) = a42*x + b42 +fit f41(x) 'ex4_UE.plot' yerr via a41, b41, c41 +fit f42(x) 'ex4_IE_1.plot' yerr via a42, b42 + +#f61(x) = log(a61*x + b61) + c61 +#f62(x) = x/a62 * exp(-x/a62 + b62) +#fit f61(x) 'ex6_UI.plot' xyerr via a61, b61, c61 +#fit f62(x) 'ex6_nuR.plot' xyerr via a62, b62 + +set linetype 10 dashtype (15, 15) lw 1 lc 0 + +set linetype 1 lc rgb "red" +set linetype 2 lc rgb "green" +set linetype 3 lc rgb "blue" + + +set output 'ex1.png' +set title "Зависимость освещённости E от расстояния до источника L^{-2}" +set xlabel "L^{-2}, м^{-2}" +set ylabel "E, лк" +set xrange[0:110] +set yrange[0:3500] + +plot 'ex1_EL.plot' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2, \ + f1(x) title "МНК" lc rgb "red" + + +reset + +set output 'ex2.png' +set title "Зависимосьть I, U фотоида от освещённости E" +set y2tics +set xlabel "E, лк" +set ylabel "U, В" +set y2label "I, А" +set xrange[0:3500] + + +plot 'ex2_IE.plot' axis x1y2 with lines title "I(E)",\ + 'ex2_UE.plot' axis x1y1 with lines title "U(E)",\ + 'ex2_IE.plot' axis x1y2 with yerrorbars notitle,\ + 'ex2_UE.plot' axis x1y1 with yerrorbars notitle,\ + f21(x) axis x1y2 lt 10 notitle, f22(x) axis x1y1 lt 10 notitle + +reset + +set output 'ex3.png' +set term pngcairo size 1272, 900 +set title "ВАХ фотоида при разных значениях освещённости" +set xlabel "U, В" +set ylabel "I, А" +set xrange[-11:0.6] + +plot 'ex3_1.plot' with lines title "I(U) с засветкой",\ + 'ex3_2.plot' with lines title "I(U) без засветки",\ + 'ex3_2.plot' using 1:2:3:4 with xyerrorbars notitle, \ + 'ex3_1.plot' using 1:2:3:4 with xyerrorbars notitle,\ +# f31(x) notitle lt 10, f32(x) notitle lt 10 + +set title "ВАХ фотоида при разных значениях освещённости (Отрицательная ветка)" +set output 'ex3_left.png' +set yrange[-0.00000255:0.0000025] + +replot + +set title "ВАХ фотоида при разных значениях освещённости (Положительная ветка)" +set output 'ex3_right.png' +unset yrange +set xrange[0:0.5] +replot + +reset +set term pngcairo size 1000, 800 +set output 'ex4.png' + +set title "Зависимосьть I, U фотоида от освещённости E" +set y2tics +set xlabel "E, лк" +set ylabel "U, В" +set y2label "I, А" +set xrange[0:3500] + +plot 'ex4_UE.plot' axis x1y1 with lines title "U(E)",\ + 'ex4_IE_1.plot' axis x1y2 with lines title "I_1(E)",\ + 'ex4_IE_2.plot' axis x1y2 with lines title "I_2(E)",\ + 'ex4_IE_1.plot' axis x1y2 with yerrorbars notitle,\ + 'ex4_IE_2.plot' axis x1y2 with yerrorbars notitle,\ + 'ex4_UE.plot' axis x1y1 with yerrorbars notitle,\ + f41(x) lt 10 notitle , f42(x) axis x1y2 lt 10 notitle + +reset + +set output 'ex6_1.png' +set title "ВАХ Солнечной батареи" +set xlabel "U, В" +set ylabel "I, А" + +plot 'ex6_UI.plot' with lines title "I(U)",\ + 'ex6_UI.plot' notitle with xyerrorbars lt 3,\ +# f61(x) lt 10 notitle + +set output 'ex6_2.png' +set title "Зависимость КПД Nu от сопротивления R" +set xlabel "Nu, ед." +set ylabel "R, кОм" +plot 'ex6_nuR.plot' with lines title "Nu(R)",\ + 'ex6_nuR.plot' notitle lt 3,\ +# f62(x) notitle lt 10 |