diff options
Diffstat (limited to '110')
-rw-r--r-- | 110/__common | 2 | ||||
-rw-r--r-- | 110/__data1 | 8 | ||||
-rw-r--r-- | 110/__main.cpp | 117 | ||||
-rw-r--r-- | 110/common | 2 | ||||
-rw-r--r-- | 110/commtst | 2 | ||||
-rw-r--r-- | 110/data1 | 4 | ||||
-rw-r--r-- | 110/listing.tex | 151 | ||||
-rw-r--r-- | 110/main.cpp | 74 | ||||
-rw-r--r-- | 110/plots.gp | 18 | ||||
-rw-r--r-- | 110/t1sts | 7 |
10 files changed, 333 insertions, 52 deletions
diff --git a/110/__common b/110/__common new file mode 100644 index 0000000..3e691bd --- /dev/null +++ b/110/__common @@ -0,0 +1,2 @@ +R1 R2 x0_1 x2_1 x4_1 m1 R2_0 R2_1 m2_0 m2_1 x0_2 x3_2 x4_2 +0.0097 0.0148 0.745 0 0.04 0.20145 0.0148 0.0097 0.20145 0.12977 0.76 0.75 0.10 diff --git a/110/__data1 b/110/__data1 new file mode 100644 index 0000000..0780865 --- /dev/null +++ b/110/__data1 @@ -0,0 +1,8 @@ +x3 x11 x12 x13 t1 t2 t3 +0.76 0.575 0.573 0.578 5.952 5.672 5.878 +0.72 0.548 0.564 0.560 5.683 5.572 5.711 +0.65 0.503 0.498 0.505 5.041 5.173 5.059 +0.60 0.465 0.466 0.469 4.862 4.776 4.728 +0.55 0.429 0.466 0.469 4.593 4.520 4.519 +0.50 0.391 0.400 0.402 4.097 4.077 4.244 +0.40 0.329 0.327 0.325 3.640 3.612 3.629 diff --git a/110/__main.cpp b/110/__main.cpp new file mode 100644 index 0000000..c7667de --- /dev/null +++ b/110/__main.cpp @@ -0,0 +1,117 @@ +#include <iostream> + +#include "include/praktable.hpp" + +using table = prak::table<double>; +using vecarg = const std::vector<f64> &; +using f64p = prak::pvalue<f64>; +table data; + +const f64p g = {9.815710602, 0.001}; + +f64 get(std::string key) { + return data[key, 0]; +} + +// [0] = x0 +f64 getsqrt(vecarg v) { + return std::sqrt(std::abs(get("x0_1") - v[0])); +} + +f64 a_A(vecarg a) { + return 2/a[0]/a[0]; +} + +f64 J_mrga(vecarg a) { + return a[0] * a[1] * a[1] * (a[2]/a[3] - 1); +} + +f64 ξ_x012(vecarg x) { + return (x[1] - x[0]) / (2*x[2] - x[0] - x[1]); +} + +f64 Mfr_mgRξ(vecarg a) { + return a[0] * a[1] * a[2] * a[3]; +} + +f64 J_mrgtx034(vecarg a) { + return a[0]*a[1]*a[1]*(a[2]*a[3]*a[3] / 2 / std::pow(std::sqrt(a[4]-a[6]) - std::sqrt(a[4]-a[5]), 2) - 1); +} + +table ex1(std::string s) { + table ret(s); + ret.add_column("x1", std::vector<f64>(ret.rows, NAN)) + .add_column("t", std::vector<f64>(ret.rows, NAN)) + .add_column("st", std::vector<f64>(ret.rows, NAN)) + .add_column("sqrt", std::vector<f64>(ret.rows, NAN)) + .apply(prak::avg<f64>, {"x11", "x12", "x13"}, "x1") + .apply(prak::avg<f64>, {"t1", "t2", "t3"}, "t") + .apply(prak::stddev<f64>, {"t1", "t2", "t3"}, "st") + .apply(getsqrt, {"x3"}, "sqrt") + .delete_cols({"x11", "x12", "x13", "t1", "t2", "t3"}); + auto [A, B] = ret.least_squares_linear("sqrt", "t", "st", std::nullopt); + + f64p m1 = {get("m1"), 0.00001}, + R = {get("R2"), 0.00005}, + x0 = {get("x0_1"), 0.01}, + x1 = {ret.col_avg("x1"), 0.01 * std::sqrt(ret.rows)}, + x2 = {get("x2_1"), 0.01}; + + /*std::cout << x0 << '\n' << x1 << '\n' << x2 << '\n';*/ + f64p a = prak::function<f64>(a_A, {A}); + f64p J = prak::function<f64>(J_mrga, {m1, R, g, a}); + f64p ξ = prak::function<f64>(ξ_x012, {x0, x1, x2}); + f64p Mfr = prak::function<f64>(Mfr_mgRξ, {m1, g, R, ξ}); + std::cout << ret + << "\na = " << a + << "\nJ = " << J + << "\nξ = " << ξ + << "\nМомент трения Mfr = " << Mfr + << std::endl; + return ret; +} + +void ex2(std::string data) { + table table(data); + f64p R0 = {get("R2_0"), 0.00005}, + R1 = {get("R2_1"), 0.00005}, + m0 = {get("m2_0"), 0.00001}, + m1 = {get("m2_1"), 0.00001}, + x0 = {get("x0_2"), 0.01}, + x3 = {get("x3_2"), 0.01}, + x4 = {get("x4_2"), 0.01}; + + table .add_column("t", std::vector<f64>(table.rows, NAN)) + .add_column("st", std::vector<f64>(table.rows, NAN)) + .add_column("Ji", std::vector<f64>(table.rows, NAN)) + .add_column("sJi", std::vector<f64>(table.rows, NAN)) + .add_column("0", std::vector<f64>(table.rows, 0.0)) + .apply(prak::avg<f64>, {"t1", "t2", "t3"}, "t") + .apply(prak::stddev<f64>, {"t1", "t2", "t3"}, "st") + .delete_cols({"t1", "t2", "t3"}) + ; + for (size_t i = 0; i < table.rows; ++i) { + /* mrgtx034 */ + std::vector<f64p> args = { + table["M", i] == 0 ? m0 : m1, + table["R", i] == 0 ? R0 : R1, + g, {table["t", i], table["st", i]}, + // я проебался и только на первом измерении у меня x4 = 4см, на остальных 10см + x0, x3, table["M", i] == 0 && table["R", i] == 0 ? f64p{0.04, 0.01} : x4, + }; + auto [val, err] = prak::function<f64>(J_mrgtx034, args); + table["Ji", i] = val; + table["sJi", i] = err; + } + table.write_plot("ex2_1.plot", "Ji", "0", "sJi"); + table.multiply_column("sJi", 1 / std::sqrt(1 - 0.75)); + table.write_plot("ex2_2.plot", "Ji", "0", "sJi"); + std::cout << table; +} + +int main() { + data = table("common"); + ex1("data1"); + ex2("data2"); + return 0; +} @@ -1,2 +1,2 @@ R1 R2 x0_1 x2_1 x4_1 m1 R2_0 R2_1 m2_0 m2_1 x0_2 x3_2 x4_2 -0.0194 0.0296 0.745 0 0.04 0.20145 0.0296 0.0194 0.20145 0.12977 0.76 0.76 0.1 +0.0097 0.0148 0.745 0 0.04 0.20145 0.0148 0.0097 0.20145 0.12977 0.76 0.72 0.10 diff --git a/110/commtst b/110/commtst new file mode 100644 index 0000000..304808c --- /dev/null +++ b/110/commtst @@ -0,0 +1,2 @@ +R1 R2 x0_1 x2_1 x4_1 m1 R2_0 R2_1 m2_0 m2_1 x0_2 x3_2 x4_2 +0.0095 0.015 0.765 0 0.05 0.20145 0.0148 0.0097 0.20145 0.12977 0.76 0.75 0.10 @@ -1,6 +1,6 @@ x3 x11 x12 x13 t1 t2 t3 -0.76 0.575 0.573 0.578 5.683 5.572 5.711 -0.72 0.548 0.564 0.560 5.952 5.672 5.878 +0.76 0.575 0.573 0.578 5.952 5.672 5.878 +0.72 0.548 0.564 0.560 5.683 5.572 5.711 0.65 0.503 0.498 0.505 5.041 5.173 5.059 0.60 0.465 0.466 0.469 4.862 4.776 4.728 0.55 0.429 0.466 0.469 4.593 4.520 4.519 diff --git a/110/listing.tex b/110/listing.tex new file mode 100644 index 0000000..23ec940 --- /dev/null +++ b/110/listing.tex @@ -0,0 +1,151 @@ +\documentclass{article} + +\usepackage[margin=0.3in]{geometry} +\usepackage{fontspec} +\usepackage{minted} +\usepackage{amsmath} + +\setmainfont{FreeSans} +\setmonofont{FreeMono} + +\begin{document} +\begin{minted}[linenos, frame=lines, fontsize=\scriptsize]{cpp} +#include <iostream> +#include "include/praktable.hpp" +using table = prak::table<double>; +using vecarg = const std::vector<f64> &; +using f64p = prak::pvalue<f64>; +table data; +const f64p g = {9.815710602, 0.001}; +f64 get(std::string key) { return data[key, 0]; } +f64 getsqrt(vecarg v) { return std::sqrt(std::abs(get("x4_1") - v[0])); } +f64 a_A(vecarg a) { return 2/a[0]/a[0]; } +f64 J_mrga(vecarg a) { return a[0] * a[1] * a[1] * (a[2]/a[3] - 1); } +f64 ξ_x012(vecarg x) { return (x[1] - x[0]) / (2*x[2] - x[0] - x[1]); } +f64 Mfr_mgRξ(vecarg a) { return a[0] * a[1] * a[2] * a[3]; } +f64 J_mrgtx034(vecarg a) { return a[0]*a[1]*a[1]*(a[2]*a[3]*a[3] / 2 / std::pow(std::sqrt(a[4]-a[6]) - std::sqrt(a[4]-a[5]), 2) - 1); } +table ex1(std::string s) { + table ret(s); + const f64 dx03 = 0.04; + + f64p m1 = {get("m1"), 0.00001}, + R = {get("R2"), 0.00005}, + x2 = {get("x2_1"), 0.01}; + + ret .add_column("x1", std::vector<f64>(ret.rows, NAN)) + .add_column("t", std::vector<f64>(ret.rows, NAN)) + .add_column("st", std::vector<f64>(ret.rows, NAN)) + .add_column("sqrt", std::vector<f64>(ret.rows, NAN)) + .add_column("x0", std::vector<f64>(ret.rows, NAN)) + .add_column("ξ", std::vector<f64>(ret.rows, NAN)) + .apply([dx03](vecarg a){return a[0]+dx03;}, {"x3"}, "x0") + .apply(prak::avg<f64>, {"x11", "x12", "x13"}, "x1") + .apply(prak::avg<f64>, {"t1", "t2", "t3"}, "t") + .apply(prak::stddev<f64>, {"t1", "t2", "t3"}, "st") + .apply(getsqrt, {"x0"}, "sqrt") + .apply([x2](vecarg a){return (a[0]-a[1])/((x2.val-a[0])+(x2.val-a[1]));}, {"x0", "x1"}, "ξ") + .delete_cols({"x11", "x12", "x13", "t1", "t2", "t3"}); + + f64p x1 = {ret.col_avg("x1"), 0.01 * std::sqrt(ret.rows)}; + auto [A, B] = ret.least_squares_linear("sqrt", "t", "st", std::nullopt); + f64p a = prak::function<f64>(a_A, {A}); + f64p J = prak::function<f64>(J_mrga, {m1, R, g, a}); + f64p ξ = {ret.col_avg("ξ"), ret.col_stddev("ξ")}; + f64p Mfr = prak::function<f64>(Mfr_mgRξ, {m1, g, R, ξ}); + ret.write_plot("mnk.plot", "sqrt", "t", "st"); + std::cout << ret << "\nA = " << A << "\nB = " << B + << "\na = " << a << "\nJ = " << J + << "\nξ = " << ξ << "\nМомент трения Mfr = " << Mfr + << std::endl; + return ret; +} +void ex2(std::string data) { + table table(data); + f64p R0 = {get("R2_0"), 0.00005}, + R1 = {get("R2_1"), 0.00005}, + m0 = {get("m2_0"), 0.00001}, + m1 = {get("m2_1"), 0.00001}, + x0 = {get("x0_2"), 0.01}, + x3 = {get("x3_2"), 0.01}, + x4 = {get("x4_2"), 0.01}; + + table .add_column("t", std::vector<f64>(table.rows, NAN)) + .add_column("st", std::vector<f64>(table.rows, NAN)) + .add_column("Ji", std::vector<f64>(table.rows, NAN)) + .add_column("sJi", std::vector<f64>(table.rows, NAN)) + .add_column("0", std::vector<f64>(table.rows, 0.0)) + .apply(prak::avg<f64>, {"t1", "t2", "t3"}, "t") + .apply(prak::stddev<f64>, {"t1", "t2", "t3"}, "st") + .delete_cols({"t1", "t2", "t3"}) + ; + for (size_t i = 0; i < table.rows; ++i) { + std::vector<f64p> args = { + table["M", i] == 0 ? m0 : m1, + table["R", i] == 0 ? R0 : R1, + g, {table["t", i], table["st", i]}, + // я пр--бался и только на первом измерении у меня x4 = 4см, на остальных 10см + x0, x3, table["M", i] == 0 && table["R", i] == 0 ? f64p{0.04, 0.01} : x4, + }; + auto [val, err] = prak::function<f64>(J_mrgtx034, args); + table["Ji", i] = val; + table["sJi", i] = err; + } + table.write_plot("ex2_1.plot", "Ji", "0", "sJi"); + table.multiply_column("sJi", 1 / std::sqrt(1 - 0.75)); + table.write_plot("ex2_2.plot", "Ji", "0", "sJi"); + std::cout << table; +} +int main() { + data = table("common"); + ex1("data1"); + ex2("data2"); + return 0; +}\end{minted} + +\newpage + +\begin{minted}[linenos, frame=lines]{gnuplot} +set term pngcairo size 1000, 800 +set title "МНК t от (x_4 - x_0)^{1/2}" +set output "mnk.png" + +f(x) = a1*x+b1 +fit f(x) 'mnk.plot' using 1:2:3 yerror via a1, b1 + +set xlabel "(x_4 - x_0)^{1/2}, м^{1/2}" +set ylabel "t, c" + +plot 'mnk.plot' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2,\ + f(x) title "t" lc rgb "#a889e7" lw 2 + +reset + +set output 'compar.png' +set title "Расположение J_i на оси J (пунктир: погрешность с коэффициентом доверия a=75%)" + +set multiplot layout 4,1 + +set linetype 10 dashtype (5, 10) + +unset ytics +unset ylabel +unset xlabel + +set xrange[0.012:0.022] +set yrange[-1:1] +plot 'ex2_1.plot' every ::0::0 using 1:2:3 with xerrorbars title "J_1" lc 0 pt 1 lw 2,\ + 'ex2_2.plot' every ::0::0 using 1:2:3 with xerrorbars title "J_{1_a}" lt 10 lc 0 pt 1 lw 2 +unset title +plot 'ex2_1.plot' every ::1::1 using 1:2:3 with xerrorbars title "J_2" lc 0 pt 1 lw 2,\ + 'ex2_2.plot' every ::1::1 using 1:2:3 with xerrorbars title "J_{2_a}" lt 10 lc 0 pt 1 lw 2 +plot 'ex2_1.plot' every ::2::2 using 1:2:3 with xerrorbars title "J_3" lc 0 pt 1 lw 2,\ + 'ex2_2.plot' every ::2::2 using 1:2:3 with xerrorbars title "J_{3_a}" lt 10 lc 0 pt 1 lw 2 +set xlabel "J, кг*м^2" + +plot 'ex2_1.plot' every ::3::3 using 1:2:3 with xerrorbars title "J_4" lc 0 pt 1 lw 2,\ + 'ex2_2.plot' every ::3::3 using 1:2:3 with xerrorbars title "J_{4_a}" lt 10 lc 0 pt 1 lw 2 + +\end{minted} + +\end{document} + diff --git a/110/main.cpp b/110/main.cpp index 6d6d6b1..1f5bf59 100644 --- a/110/main.cpp +++ b/110/main.cpp @@ -9,63 +9,46 @@ table data; const f64p g = {9.815710602, 0.001}; -f64 get(std::string key) { - return data[key, 0]; -} - -// [0] = x0 -f64 getsqrt(vecarg v) { - return std::sqrt(std::abs(get("x0_1") - v[0])); -} - -f64 a_A(vecarg a) { - return 2/a[0]/a[0]; -} - -f64 J_mrga(vecarg a) { - return a[0] * a[1] * a[1] * (a[2]/a[3] + 1); -} - -f64 ξ_x012(vecarg x) { - return (x[1] - x[0]) / (2*x[2] - x[0] - x[1]); -} - -f64 Mfr_mgRξ(vecarg a) { - return a[0] * a[1] * a[2] * a[3]; -} - -f64 J_mrgtx034(vecarg a) { - return a[0]*a[1]*a[1]*(a[2]*a[3]*a[3] / 2 / std::pow(std::sqrt(std::abs(a[6]-a[4])) - std::sqrt(std::abs(a[5]-a[4])), 2) - 1); -} +f64 get(std::string key) { return data[key, 0]; } +f64 getsqrt(vecarg v) { return std::sqrt(std::abs(get("x4_1") - v[0])); } +f64 a_A(vecarg a) { return 2/a[0]/a[0]; } +f64 J_mrga(vecarg a) { return a[0] * a[1] * a[1] * (a[2]/a[3] - 1); } +f64 ξ_x012(vecarg x) { return (x[1] - x[0]) / (2*x[2] - x[0] - x[1]); } +f64 Mfr_mgRξ(vecarg a) { return a[0] * a[1] * a[2] * a[3]; } +f64 J_mrgtx034(vecarg a) { return a[0]*a[1]*a[1]*(a[2]*a[3]*a[3] / 2 / std::pow(std::sqrt(a[4]-a[6]) - std::sqrt(a[4]-a[5]), 2) - 1); } table ex1(std::string s) { table ret(s); - ret.add_column("x1", std::vector<f64>(ret.rows, NAN)) + const f64 dx03 = 0.04; + + f64p m1 = {get("m1"), 0.00001}, + R = {get("R2"), 0.00005}, + x2 = {get("x2_1"), 0.01}; + + ret .add_column("x1", std::vector<f64>(ret.rows, NAN)) .add_column("t", std::vector<f64>(ret.rows, NAN)) .add_column("st", std::vector<f64>(ret.rows, NAN)) .add_column("sqrt", std::vector<f64>(ret.rows, NAN)) + .add_column("x0", std::vector<f64>(ret.rows, NAN)) + .add_column("ξ", std::vector<f64>(ret.rows, NAN)) + .apply([dx03](vecarg a){return a[0]+dx03;}, {"x3"}, "x0") .apply(prak::avg<f64>, {"x11", "x12", "x13"}, "x1") .apply(prak::avg<f64>, {"t1", "t2", "t3"}, "t") .apply(prak::stddev<f64>, {"t1", "t2", "t3"}, "st") - .apply(getsqrt, {"x3"}, "sqrt") + .apply(getsqrt, {"x0"}, "sqrt") + .apply([x2](vecarg a){return (a[0]-a[1])/((x2.val-a[0])+(x2.val-a[1]));}, {"x0", "x1"}, "ξ") .delete_cols({"x11", "x12", "x13", "t1", "t2", "t3"}); - auto [A, B] = ret.least_squares_linear("sqrt", "t", "st", std::nullopt); - - f64p m1 = {get("m1"), 0.00001}, - R = {get("R1"), 0.00005}, - x0 = {get("x0_1"), 0.01}, - x1 = {ret.col_avg("x1"), ret.col_stddev("x1")}, - x2 = {get("x2_1"), 0.01}; + f64p x1 = {ret.col_avg("x1"), 0.01 * std::sqrt(ret.rows)}; + auto [A, B] = ret.least_squares_linear("sqrt", "t", "st", std::nullopt); f64p a = prak::function<f64>(a_A, {A}); f64p J = prak::function<f64>(J_mrga, {m1, R, g, a}); - f64p ξ = prak::function<f64>(ξ_x012, {x0, x1, x2}); + f64p ξ = {ret.col_avg("ξ"), ret.col_stddev("ξ")}; f64p Mfr = prak::function<f64>(Mfr_mgRξ, {m1, g, R, ξ}); - std::cout << ret - << "\na = " << a - << "\nJ = " << J - << "\nξ = " << ξ - << "\nМомент трения Mfr = " << Mfr + ret.write_plot("mnk.plot", "sqrt", "t", "st"); + std::cout << ret << "\nA = " << A << "\nB = " << B + << "\na = " << a << "\nJ = " << J + << "\nξ = " << ξ << "\nМомент трения Mfr = " << Mfr << std::endl; return ret; } @@ -88,16 +71,13 @@ void ex2(std::string data) { .apply(prak::avg<f64>, {"t1", "t2", "t3"}, "t") .apply(prak::stddev<f64>, {"t1", "t2", "t3"}, "st") .delete_cols({"t1", "t2", "t3"}) - /* .apply([&R0, &R1](vecarg a) { return a[0] == 0 ? R0.val : R1.val; }, {"R"}, "R") */ - /* .apply([&m0, &m1](vecarg a) { return a[0] == 0 ? m0.val : m1.val; }, {"M"}, "M") */ ; for (size_t i = 0; i < table.rows; ++i) { - /* mrgtx034 */ std::vector<f64p> args = { table["M", i] == 0 ? m0 : m1, table["R", i] == 0 ? R0 : R1, g, {table["t", i], table["st", i]}, - // я проебался и только на первом измерении у меня x4 = 4см, на остальных 10см + // я пр**бался и только на первом измерении у меня x4 = 4см, на остальных 10см x0, x3, table["M", i] == 0 && table["R", i] == 0 ? f64p{0.04, 0.01} : x4, }; auto [val, err] = prak::function<f64>(J_mrgtx034, args); diff --git a/110/plots.gp b/110/plots.gp index 772accd..e13f65c 100644 --- a/110/plots.gp +++ b/110/plots.gp @@ -1,5 +1,18 @@ set term pngcairo size 1000, 800 -#set tmargin at screen 0.95 +set title "МНК t от (x_4 - x_0)^{1/2}" +set output "mnk.png" + +f(x) = a1*x+b1 +fit f(x) 'mnk.plot' using 1:2:3 yerror via a1, b1 + +set xlabel "(x_4 - x_0)^{1/2}, м^{1/2}" +set ylabel "t, c" + +plot 'mnk.plot' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2,\ + f(x) title "t" lc rgb "#a889e7" lw 2 + +reset + set output 'compar.png' set title "Расположение J_i на оси J (пунктир: погрешность с коэффициентом доверия a=75%)" @@ -8,9 +21,10 @@ set multiplot layout 4,1 set linetype 10 dashtype (5, 10) unset ytics +unset ylabel unset xlabel -set xrange[0.035:0.042] +set xrange[0.012:0.022] set yrange[-1:1] plot 'ex2_1.plot' every ::0::0 using 1:2:3 with xerrorbars title "J_1" lc 0 pt 1 lw 2,\ 'ex2_2.plot' every ::0::0 using 1:2:3 with xerrorbars title "J_{1_a}" lt 10 lc 0 pt 1 lw 2 diff --git a/110/t1sts b/110/t1sts new file mode 100644 index 0000000..10b2b93 --- /dev/null +++ b/110/t1sts @@ -0,0 +1,7 @@ +x3 x11 x12 x13 t1 t2 t3 +0.75 0.615 0.625 0.615 5.731 5.866 5.862 +0.70 0.625 0.622 0.623 4.785 4.824 4.852 +0.65 0.625 0.625 0.627 4.159 4.135 4.153 +0.60 0.624 0.623 0.622 3.623 3.622 3.625 +0.55 0.62 0.63 0.63 3.148 3.143 3.132 +0.50 0.575 0.585 0.585 2.625 2.598 2.596 |