diff options
Diffstat (limited to 'vtek3/main.cpp')
-rw-r--r-- | vtek3/main.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
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); |