diff options
author | justanothercatgirl <sotov2070@gmail.com> | 2024-11-24 19:45:32 +0300 |
---|---|---|
committer | justanothercatgirl <sotov2070@gmail.com> | 2024-11-24 19:45:32 +0300 |
commit | 33e3d9540237b0faef3c7d9aeab6dedbccbe3707 (patch) | |
tree | b5e4352b130e5086bb6cca5dca4d7af728941e20 /vtek3/main.cpp | |
parent | 89d26d5d0e8ff2b026cc99606868699f6fcc08db (diff) |
107,vtek3 changes
Diffstat (limited to 'vtek3/main.cpp')
-rw-r--r-- | vtek3/main.cpp | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/vtek3/main.cpp b/vtek3/main.cpp index 6984eff..15de4c4 100644 --- a/vtek3/main.cpp +++ b/vtek3/main.cpp @@ -41,15 +41,16 @@ RT err_MS8040(const std::vector<RT> &args) { // output: DI RT D_M830B(const std::vector<RT> &args) { RT val = args[0]; - if (val < 0.002) return 1e-6; - if (val < 0.020) return 1e-5; - if (val < 0.200) return 1e-4; + if (val < 0.0002) return 1e-6; + if (val < 0.002) return 1e-5; + if (val < 0.020) return 1e-4; + if (val < 0.200) return 1e-3; return 1e-3; } // 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]; } @@ -77,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); } @@ -102,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) { @@ -141,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); |