From 89d26d5d0e8ff2b026cc99606868699f6fcc08db Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Mon, 18 Nov 2024 23:40:21 +0300 Subject: added tempalte --- vtek3/Makefile | 10 +++++++ vtek3/data_green | 12 +++++++++ vtek3/data_red | 12 +++++++++ vtek3/include | 2 +- vtek3/main | Bin 0 -> 649768 bytes vtek3/main.cpp | 79 +++++++++++++++++++++++++++++++++++++++---------------- vtek3/plots.gp | 48 +++++++++++++++++++++++++++++++++ 7 files changed, 139 insertions(+), 24 deletions(-) create mode 100644 vtek3/data_green create mode 100644 vtek3/data_red create mode 100755 vtek3/main create mode 100644 vtek3/plots.gp (limited to 'vtek3') diff --git a/vtek3/Makefile b/vtek3/Makefile index 4f9a99a..b89eb0b 100644 --- a/vtek3/Makefile +++ b/vtek3/Makefile @@ -2,5 +2,15 @@ CXXFLAGS += -std=c++2c -mavx2 -Iinclude CXXFLAGS += -ggdb +run: main + ./main + gnuplot plots.gp + main: main.cpp $(CXX) -o $@ $^ $(CXXFLAGS) + +.PHONY: clean + +clean: + rm -fr plot*.data main *.png + diff --git a/vtek3/data_green b/vtek3/data_green new file mode 100644 index 0000000..62a2831 --- /dev/null +++ b/vtek3/data_green @@ -0,0 +1,12 @@ +__name__ U DU sU I DI sI +1 1.337 ? ? 0 ? ? +2 1.7638 ? ? 0.000069 ? ? +3 1.8074 ? ? 0.000228 ? ? +4 1.8228 ? ? 0.000333 ? ? +5 1.8448 ? ? 0.000555 ? ? +6 1.8586 ? ? 0.000727 ? ? +7 1.8899 ? ? 0.001337 ? ? +8 1.9147 ? ? 0.001989 ? ? +9 1.9554 ? ? 0.003330 ? ? +10 1.9776 ? ? 0.004270 ? ? + diff --git a/vtek3/data_red b/vtek3/data_red new file mode 100644 index 0000000..442efb4 --- /dev/null +++ b/vtek3/data_red @@ -0,0 +1,12 @@ +__name__ U DU sU I DI sI +1 0.0377 ? ? 0 ? ? +2 1.5335 ? ? 0.000050 ? ? +3 1.5959 ? ? 0.000200 ? ? +4 1.6150 ? ? 0.000301 ? ? +5 1.6310 ? ? 0.000420 ? ? +6 1.6535 ? ? 0.000666 ? ? +7 1.6742 ? ? 0.001001 ? ? +8 1.7147 ? ? 0.001999 ? ? +9 1.7425 ? ? 0.003000 ? ? +10 1.7685 ? ? 0.004200 ? ? + diff --git a/vtek3/include b/vtek3/include index f5030d7..2225752 120000 --- a/vtek3/include +++ b/vtek3/include @@ -1 +1 @@ -../libprakipp/include/ \ No newline at end of file +../libprakpp/include/ \ No newline at end of file diff --git a/vtek3/main b/vtek3/main new file mode 100755 index 0000000..41834ee Binary files /dev/null and b/vtek3/main differ diff --git a/vtek3/main.cpp b/vtek3/main.cpp index 5e3d491..6984eff 100644 --- a/vtek3/main.cpp +++ b/vtek3/main.cpp @@ -37,14 +37,6 @@ RT err_MS8040(const std::vector &args) { return 0.0005 * args[0] + 6 * args[1]; } -RT S(const std::vector &args) { - return prak::PI * args[0]*args[0]/4; -} - -RT S_1(const std::vector &args) { - return 1 / S(args); -} - // args: I // output: DI RT D_M830B(const std::vector &args) { @@ -61,7 +53,7 @@ RT err_M380B(const std::vector &args) { return 0.01 * args[0] + 2 * args[1]; } -void ex1(void) { +void excercise1(void) { std::unordered_map> map { {{0.5, 0.00015}, prak::table{}}, {{0.5, 0.00025}, prak::table{}}, @@ -85,7 +77,6 @@ void ex1(void) { table.apply(D_MS8040, {"U"}, "DU") .apply(err_MS8040, {"U", "DU"}, "sU") .apply(D_M830B, {"I"}, "DI") - .apply(D_M830B, {"I"}, "DI") .apply(err_M380B, {"I", "DI"}, "sI"); std::cout << index << ":\n" << table << std::endl; if (prak::fequal(index.length, 0.5)) resist_d.add_row({index.diam, NAN, NAN, NAN, NAN}); @@ -95,33 +86,75 @@ void ex1(void) { for (size_t i = 0; i < resist_d.rows; ++i) { prak::table &cur = map.at({.length = 0.5, .diam = resist_d["d", i]}); auto [a, b] = cur.least_squares_linear("U", "I", "sI"); - std::cout << "diam = " << resist_d["d", i] - << ": A = " << a - << "; B = " << b - << "; R = " << 1/a.val << std::endl; resist_d["R", i] = 1/a.val; resist_d["sR", i] = a.err/a.val/a.val; - resist_d.apply(S_1, {"d"}, "1/S"); std::ofstream outf("plot_" + std::to_string(0.5f) + "_" + std::to_string(resist_d["d", i]) + ".data"); cur.write_plot("U", "I", "sI", outf); } + + std::ofstream rsplot("plot_r_1s.data"); + resist_d + .apply([](const std::vector &args) -> RT { + return prak::PI * args[0]*args[0]/4; + }, {"d"}, "S") + .apply([](const std::vector &args) -> RT { + return 1 / (prak::PI * args[0]*args[0]/4); + }, {"d"}, "1/S") + .write_plot("1/S", "R", "sR", rsplot); + auto [rho, _] = resist_d.least_squares_linear("1/S", "R", "sR"); rho.val /= 0.5; rho.err /= 0.5; std::cout << "Rho = " << rho << " (error = " << _ << ")" << std::endl; - + // LLS for d=const - resist_d.apply(S, {"d"}, "S") - .apply(S_1, {"d"}, "1/S"); - std::cout << resist_d; + for (size_t i = 0; i < resist_L.rows; ++i) { + prak::table &cur = map.at({.length = resist_L["L", i], .diam = 0.00015}); + auto [a, b] = cur.least_squares_linear("U", "I", "sI"); + resist_L["R", i] = 1/a.val; + resist_L["sR", i] = a.err/a.val/a.val; + } + RT _d = 0.00015; + auto rho_f = [](const std::vector &args) -> RT { + return args[1] * prak::PI * args[2] * args[2] / args[0] / 4; + }; + resist_L + .apply([_d, &rho_f](const std::vector &args) { + return rho_f({args[0], args[1], _d}); + }, {"L", "R"}, "Rho") + .apply([_d, &rho_f](const std::vector &args) -> RT { + return prak::sigma(rho_f, {args[0], args[1], _d}, {0, args[2], 0}); + }, {"L", "R", "sR"}, "sRho"); + + // output + std::cout << resist_d << resist_L; } -void ex3(void) { - +void excercise3(void) { + prak::table red, green; + { + std::ifstream red_stream("data_red"), green_stream("data_green"); + red.read(red_stream); + green.read(green_stream); + } + green .apply(D_MS8040, {"U"}, "DU") + .apply(err_MS8040, {"U", "DU"}, "sU") + .apply(D_M830B, {"I"}, "DI") + .apply(D_M830B, {"I", "DI"}, "sI"); + red .apply(D_MS8040, {"U"}, "DU") + .apply(err_MS8040, {"U", "DU"}, "sU") + .apply(D_M830B, {"I"}, "DI") + .apply(D_M830B, {"I", "DI"}, "sI"); + { + std::ofstream red_out("plot_red.data"), green_out("plot_green.data"); + red.write_plot("U", "I", "sI", red_out); + green.write_plot("U", "I", "sI", green_out); + } + std::cout << "Red: " << red << "\nGreen: " << green; } int main(int argc, char *argvp[]) { - ex1(); - ex3(); + excercise1(); + excercise3(); } diff --git a/vtek3/plots.gp b/vtek3/plots.gp new file mode 100644 index 0000000..a0e314a --- /dev/null +++ b/vtek3/plots.gp @@ -0,0 +1,48 @@ +set term pngcairo size 1000, 800 +set tmargin at screen 0.95 + +f1(x) = a1*x+b1 +f2(x) = a2*x+b2 +f3(x) = a3*x+b3 + +set output 'plot_mnk.png' +set label "Графики вольтамперных характеристик проводов разного диаметра" at graph 0.5, graph 1.025 center +set xlabel "U, В" +set ylabel "I, А" +set xrange[0:1] +set yrange[0:0.1] +fit f1(x) 'plot_0.5_0.00015.data' using 1:2:3 yerr via a1, b1 +fit f2(x) 'plot_0.5_0.00025.data' using 1:2:3 yerr via a2, b2 +fit f3(x) 'plot_0.5_4e-04.data' using 1:2:3 yerr via a3, b3 +plot \ + 'plot_0.5_0.00015.data' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2, \ + 'plot_0.5_0.00025.data' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2, \ + 'plot_0.5_4e-04.data' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2, \ + f1(x) title "d=0.15 * 10^{-3}" lc rgb "red", \ + f2(x) title "d=0.25 * 10^{-3}" lc rgb "green", \ + f3(x) title "d=0.4 * 10^{-3}" lc rgb "blue" + +set output 'plot_rs.png' +unset label +set label "График зависимости R от 1/S сечения" at graph 0.5, graph 1.025 center +unset xrange +unset yrange +set xlabel "S^{-1}, м^{-2}" +set ylabel "R, Ом" +fit f1(x) 'plot_r_1s.data' using 1:2:3 yerr via a1, b1 +plot 'plot_r_1s.data' using 1:2:3 with yerrorbars notitle lc rgb "red" pt 1 lw 2, \ + f1(x) title "R" lc 0 + +set out + +set output 'plot_diods.png' +unset label +set label "Вольтамперная характеристика красного и синего светодиодов" at graph 0.5, graph 1.025 center +set xlabel "U, В" +set ylabel "Y, A" +set xrange[1:2] +plot 'plot_red.data' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2, \ + 'plot_green.data' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2, \ + 'plot_red.data' with lines lc rgb "red" title "I(U) красный", \ + 'plot_green.data' with lines lc rgb "green" title "I(U) зелёный" + -- cgit v1.2.3-70-g09d2