aboutsummaryrefslogtreecommitdiffstats
path: root/vtek3
diff options
context:
space:
mode:
Diffstat (limited to 'vtek3')
-rw-r--r--vtek3/Makefile2
-rwxr-xr-xvtek3/mainbin650040 -> 0 bytes
-rw-r--r--vtek3/main.cpp40
-rw-r--r--vtek3/plots.gp45
4 files changed, 64 insertions, 23 deletions
diff --git a/vtek3/Makefile b/vtek3/Makefile
index b89eb0b..fd22144 100644
--- a/vtek3/Makefile
+++ b/vtek3/Makefile
@@ -4,7 +4,7 @@ CXXFLAGS += -ggdb
run: main
./main
- gnuplot plots.gp
+ gnuplot -q plots.gp 2> /dev/null
main: main.cpp
$(CXX) -o $@ $^ $(CXXFLAGS)
diff --git a/vtek3/main b/vtek3/main
deleted file mode 100755
index a541052..0000000
--- a/vtek3/main
+++ /dev/null
Binary files differ
diff --git a/vtek3/main.cpp b/vtek3/main.cpp
index 5b86cca..15de4c4 100644
--- a/vtek3/main.cpp
+++ b/vtek3/main.cpp
@@ -50,7 +50,7 @@ RT D_M830B(const std::vector<RT> &args) {
// args: I, DI
// output: sI
-RT err_M380B(const std::vector<RT> &args) {
+RT err_M830B(const std::vector<RT> &args) {
return 0.01 * args[0] + 2 * args[1];
}
@@ -78,18 +78,20 @@ void excercise1(void) {
table.apply(D_MS8040, {"U"}, "DU")
.apply(err_MS8040, {"U", "DU"}, "sU")
.apply(D_M830B, {"I"}, "DI")
- .apply(err_M380B, {"I", "DI"}, "sI");
+ .apply(err_M830B, {"I", "DI"}, "sI");
std::cout << index << ":\n" << table << std::endl;
if (prak::fequal<RT>(index.length, 0.5)) resist_d.add_row({index.diam, NAN, NAN, NAN, NAN});
if (prak::fequal<RT>(index.diam, 0.00015)) resist_L.add_row({index.length, NAN, NAN, NAN, NAN});
}
// LLS for L=const
for (size_t i = 0; i < resist_d.rows; ++i) {
- prak::table<RT> &cur = map.at({.length = 0.5, .diam = resist_d["d", i]});
+ RT diam = resist_d["d", i];
+ prak::table<RT> &cur = map.at({.length = 0.5, .diam = diam});
auto [a, b] = cur.least_squares_linear("U", "I", "sI");
resist_d["R", i] = 1/a.val;
resist_d["sR", i] = a.err/a.val/a.val;
- std::ofstream outf("plot_" + std::to_string(0.5f) + "_" + std::to_string(resist_d["d", i]) + ".data");
+ std::cout << "МНК для L=const, d=" << diam << ": " << "A=" << a << "; B=" << b << std::endl;
+ std::ofstream outf("plot_" + std::to_string(0.5f) + "_" + std::to_string(diam) + ".data");
cur.write_plot("U", "I", "sI", outf);
}
@@ -103,33 +105,43 @@ void excercise1(void) {
}, {"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;
+ auto [rhod_a, rhod_b] = resist_d.least_squares_linear("1/S", "R", "sR");
+ rhod_a.val /= 0.5;
+ rhod_a.err /= 0.5;
+ std::cout << "МНК для Rho_d = " << rhod_a*2.0f << " (error = " << rhod_b*2.0f << ")" << std::endl;
+ std::cout << "Rho = " << rhod_a << " (error = " << rhod_b << ")" << std::endl;
// LLS for d=const
for (size_t i = 0; i < resist_L.rows; ++i) {
- prak::table<RT> &cur = map.at({.length = resist_L["L", i], .diam = 0.00015});
+ RT length = resist_L["L", i];
+ prak::table<RT> &cur = map.at({.length = length, .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;
+ std::cout << "МНК для d=const, L=" << length << ": " << "A=" << a << "; B=" << b << std::endl;
+ std::ofstream outf("plot_" + std::to_string(length) + "_" + std::to_string(0.00015f) + ".data");
+ cur.write_plot("U", "I", "sI", outf);
}
+
RT _d = 0.00015;
auto rho_f = [](const std::vector<RT> &args) -> RT {
return args[1] * prak::PI * args[2] * args[2] / args[0] / 4;
};
+ std::ofstream rlplot("plot_r_l.data");
resist_L
.apply([_d, &rho_f](const std::vector<RT> &args) {
return rho_f({args[0], args[1], _d});
}, {"L", "R"}, "Rho")
.apply([_d, &rho_f](const std::vector<RT> &args) -> RT {
return prak::sigma<RT>(rho_f, {args[0], args[1], _d}, {0, args[2], 0});
- }, {"L", "R", "sR"}, "sRho");
-
+ }, {"L", "R", "sR"}, "sRho")
+ .write_plot("L", "R", "sR", rlplot);
+ auto [_1, _2] = resist_L.least_squares_linear("L", "R", "sR");
+ RT d_15_s = 0.00015 * 0.00015 * prak::PI / 4;
+ std::cout << "МНК для Rho_L = " << _1 << " (error = " << _2 << ")" << std::endl;
+ std::cout << "Rho_L = " << _1 * d_15_s << " (error = " << _2 * d_15_s << ")" << std::endl;
// output
std::cout << resist_d << resist_L;
-
}
void excercise3(void) {
@@ -142,11 +154,11 @@ void excercise3(void) {
green .apply(D_MS8040, {"U"}, "DU")
.apply(err_MS8040, {"U", "DU"}, "sU")
.apply(D_M830B, {"I"}, "DI")
- .apply(D_M830B, {"I", "DI"}, "sI");
+ .apply(err_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");
+ .apply(err_M830B, {"I", "DI"}, "sI");
{
std::ofstream red_out("plot_red.data"), green_out("plot_green.data");
red.write_plot("U", "I", "sI", red_out);
diff --git a/vtek3/plots.gp b/vtek3/plots.gp
index a0e314a..64261c9 100644
--- a/vtek3/plots.gp
+++ b/vtek3/plots.gp
@@ -5,7 +5,8 @@ f1(x) = a1*x+b1
f2(x) = a2*x+b2
f3(x) = a3*x+b3
-set output 'plot_mnk.png'
+set output 'plot_mnk_lconst.png'
+unset label
set label "Графики вольтамперных характеристик проводов разного диаметра" at graph 0.5, graph 1.025 center
set xlabel "U, В"
set ylabel "I, А"
@@ -14,17 +15,35 @@ 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 \
'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"
+ 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.40 * 10^{-3} м" lc rgb "blue"
+set output 'plot_mnk_dconst.png'
+unset label
+set label "Графики вольтамперных характеристик проводов разной длины" at graph 0.5, graph 1.025 center
+set xlabel "U, В"
+set ylabel "I, А"
+unset xrange
+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_1_0.00015.data' using 1:2:3 yerr via a2, b2
+fit f3(x) 'plot_1.5_0.00015.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_1_0.00015.data' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2, \
+ 'plot_1.5_0.00015.data' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2, \
+ f1(x) title "L = 0.5 м" lc rgb "red", \
+ f2(x) title "L = 1.0 м" lc rgb "green", \
+ f3(x) title "L = 1.5 м" lc rgb "blue"
+
set output 'plot_rs.png'
unset label
-set label "График зависимости R от 1/S сечения" at graph 0.5, graph 1.025 center
+set label "График зависимости сопротивления R от 1/S сечения" at graph 0.5, graph 1.025 center
unset xrange
unset yrange
set xlabel "S^{-1}, м^{-2}"
@@ -33,13 +52,23 @@ 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_rl.png'
+unset label
+set label "График зависимости сопротивления R от длины провода L" at graph 0.5, graph 1.025 center
+unset xrange
+unset yrange
+set xlabel "L, м"
+set ylabel "R, Ом"
+fit f1(x) 'plot_r_l.data' using 1:2:3 yerr via a1, b1
+plot 'plot_r_l.data' using 1:2:3 with yerrorbars notitle lc rgb "red" pt 1 lw 2, \
+ f1(x) title "R" lc 0
+
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 ylabel "I, 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, \