diff options
author | justanothercatgirl <sotov2070@gmail.com> | 2025-02-24 21:26:32 +0300 |
---|---|---|
committer | justanothercatgirl <sotov2070@gmail.com> | 2025-02-24 21:26:32 +0300 |
commit | e10c7380486e07b277001ab3aa653b74aa990f79 (patch) | |
tree | 56911e9760a43f9753fb0190952eaf4fd9ad6151 | |
parent | 8269ece153d9f8d1a8a5fb7238adce6aa4226f99 (diff) |
Added 227
-rw-r--r-- | 227/Makefile | 18 | ||||
-rw-r--r-- | 227/README.md | 5 | ||||
-rw-r--r-- | 227/compile_flags.txt | 4 | ||||
-rw-r--r-- | 227/data1 | 6 | ||||
l--------- | 227/include | 1 | ||||
-rw-r--r-- | 227/main.cpp | 83 | ||||
-rw-r--r-- | 227/plots.gp | 31 | ||||
-rw-r--r-- | libprakpp/include/prakcommon.hpp | 41 | ||||
-rw-r--r-- | libprakpp/include/prakmath.hpp | 42 | ||||
-rw-r--r-- | libprakpp/include/prakphys.hpp | 28 | ||||
-rw-r--r-- | tempalte/plots.gp | 1 | ||||
-rw-r--r-- | vtek7/main.cpp | 8 | ||||
-rw-r--r-- | vtek7/plots.gp | 6 |
13 files changed, 241 insertions, 33 deletions
diff --git a/227/Makefile b/227/Makefile new file mode 100644 index 0000000..224506f --- /dev/null +++ b/227/Makefile @@ -0,0 +1,18 @@ + +CFLAGS = -std=c++2c -mavx -Iinclude -ggdb + +.PHONY: all run_main clean gnuplot + +run: gnuplot + +gnuplot: plots.gp run_main + gnuplot $< &>/dev/null + +run_main: main + ./main + +main: main.cpp include/* + $(CXX) -o $@ $< $(CFLAGS) + +clean: + rm -fr main *.png *.plot diff --git a/227/README.md b/227/README.md new file mode 100644 index 0000000..96fd716 --- /dev/null +++ b/227/README.md @@ -0,0 +1,5 @@ +<!-- Шаблон для прака --> +<!-- файлы, заканчивающиеся на .plot считаются генерируемыми и удаляются через make clean --> +# Обработка <> прака + + diff --git a/227/compile_flags.txt b/227/compile_flags.txt new file mode 100644 index 0000000..34ae930 --- /dev/null +++ b/227/compile_flags.txt @@ -0,0 +1,4 @@ +-Iinclude +-std=c++2c +-mavx2 + diff --git a/227/data1 b/227/data1 new file mode 100644 index 0000000..3e94706 --- /dev/null +++ b/227/data1 @@ -0,0 +1,6 @@ +T h1 h2 p sp ln(p) 1/T t1 t2 t3 t st nu snu +27.5 11.9 9.3 ? ? ? ? 77.1 76.5 78.1 ? ? ? ? +29.5 12.0 9.2 ? ? ? ? 71.5 69.9 70.1 ? ? ? ? +34.5 12.5 8.8 ? ? ? ? 51 48.9 48.8 ? ? ? ? +37.5 12.8 8.5 ? ? ? ? 41.3 40.5 41.8 ? ? ? ? +40.0 13.1 8.1 ? ? ? ? 36.1 37.0 35.9 ? ? ? ? diff --git a/227/include b/227/include new file mode 120000 index 0000000..2225752 --- /dev/null +++ b/227/include @@ -0,0 +1 @@ +../libprakpp/include/
\ No newline at end of file diff --git a/227/main.cpp b/227/main.cpp new file mode 100644 index 0000000..7c4c912 --- /dev/null +++ b/227/main.cpp @@ -0,0 +1,83 @@ +#include <iostream> + +#include "include/praktable.hpp" +#include "include/prakphys.hpp" + +using table = prak::table<f64>; +using f64p = prak::pvalue<f64>; +using f64v = std::vector<f64>; +using vecarg = const std::vector<f64> &; +using argvec = const std::vector<f64> &; + +template <typename T> +std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { + os << "{ "; + for (const auto& val: vec) os << val << ", "; + os << "} "; + return os; +} + +auto ex1(std::string file) { + table t(file); + t.column_width = 12; + std::cout << t + .apply(prak::diff<f64>, {"h1", "h2"}, "p") + .fill_column("sp", 0.1 * std::sqrt(2.0)) + .apply(prak::log<f64>, {"p"}, "ln(p)") + .add_column("s_ln(p)") + .apply(prak::quot<f64>, {"sp", "p"}, "s_ln(p)") + .apply(prak::add<f64, conv::C_to_K<f64>>, {"T"}, "T") + .apply(prak::inv<f64>, {"T"}, "1/T") + .apply(prak::avg<f64>, {"t1", "t2", "t3"}, "t") + .apply(prak::stddev<f64>, {"t1", "t2", "t3"}, "st") + .delete_cols({"t1", "t2", "t3"}) + .write_plot("plot_lnp.plot", "1/T", "ln(p)", "s_ln(p)"); + auto [A, B] = t.least_squares_linear("1/T", "ln(p)", "s_ln(p)", std::nullopt); + std::cout << "Мнк ln(p) от (1/T): " << A << ' ' << B << std::endl; + f64 a_tbl = .5451, mu = .09209, v_w = .00100177, v_s = 57.8; + f64p Q = A * (-prak::R<f64>); + f64p q = Q/mu, p = 1333.2239023154 * (f64p){t["p", 4], t["sp", 4]}; + f64p a = mu*mu*(q - p*v_s)*v_w; + std::cout << "\nmu = " << mu << ", v_воды = " << v_w << ", v_пар = " << v_s << ", p = " << p << " (темература 20 по методу наглых подгонов)" + << "\nQ = " << Q << ", q = " << q << ", a = " << a << ", a_теор = " << a_tbl << ", отклонение = " << a_tbl - a << std::endl; + return t; +} + +void ex2(prak::table<f64> t) { + f64 beta = 6.1e-4, rho_0 = 1263.6, rho_1 = 8131, T_0 = 20 + conv::C_to_K<f64>, K = 114.4e-3, mu = .09209; + t .add_column("rho_2") + .apply([=](vecarg a){ return rho_0 / (1 + beta * (a[0] - T_0)); }, {"T"}, "rho_2") + .add_column("s_rho_2", 0.000001) + .apply_function_n( [=](vecarg a){ return K * (rho_1 - a[0]) * a[1]; }, + {t.begin("rho_2"), t.begin("t")}, + {t.begin("s_rho_2"), t.begin("st")}, + t.rows, "nu", "snu") + .add_column("ln(nu)", NAN) + .add_column("s_ln(nu)", NAN) + .apply_function_n(prak::log<f64>, {t.begin("nu")}, {t.begin("snu")}, t.rows, "ln(nu)", "s_ln(nu)") + .add_column("1/nu", NAN) + .add_column("s_1/nu", NAN) + .add_column("1/rho_2", NAN) + .apply(prak::inv<f64>, {"nu"}, "1/nu") + .apply([](vecarg a){ return a[1] / a[0] / a[0]; }, {"nu", "snu"}, "s_1/nu") + .apply(prak::inv<f64>, {"rho_2"}, "1/rho_2") + .delete_cols({"h1", "h2", "p", "sp", "ln(p)", "t", "st"}) + .write_plot("plot_lnn.plot", "1/T", "ln(nu)", "s_ln(nu)") + .write_plot("plot_nut.plot", "1/rho_2", "1/nu", "s_1/nu") + .print(); + auto [A, B] = t.least_squares_linear("1/T", "ln(nu)", "s_ln(nu)", std::nullopt); + f64p eps = prak::k<f64> * A; + std::cout + << "Мнк ln(p) (1/T): (" << A << ")x + (" << B << ")\n" + << "энергия активации: " << eps * conv::J_to_eV<f64> << "эВ" << std::endl; + auto [A1, B1] = t.least_squares_linear("1/rho_2", "1/nu", "s_1/nu", std::nullopt); + f64p c = A / mu, b = -mu * B / A; + std::cout + << "Мнк 1/nu (1/rho_2): (" << A1 << ")x + (" << B1 << ")\n" + << "b = " << b << "; c = " << c << std::endl; +} + +int main() { + ex2(ex1("data1")); + return 0; +} diff --git a/227/plots.gp b/227/plots.gp new file mode 100644 index 0000000..8413681 --- /dev/null +++ b/227/plots.gp @@ -0,0 +1,31 @@ +set term pngcairo size 1000, 800 +set grid + +f1(x) = a1*x+b1 +fit f1(x) 'plot_lnp.plot' using 1:2:3 yerr via a1, b1 + +set output 'plot_lnp.png' +set title "Зависимость логарифма давления от обратной температуры" +set xlabel "K^{-1}" +set ylabel "ln(p), ln(см.рт.ст)" +plot 'plot_lnp.plot' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2, \ + f1(x) title "" lc rgb "red" + + +set output 'plot_lnn.png' +set title "Зависимость логарифма динамической вязкости от обратной температы" +set ylabel "ln(nu)" +fit f1(x) 'plot_lnn.plot' using 1:2:3 yerr via a1, b1 +plot 'plot_lnn.plot' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2,\ + f1(x) title "" lc rgb "red" + + +set output 'plot_nut.png' +set title "Зависимость обратной динамической вязкости от обратной плотности" +set xlabel "1/rho, м^3/кг" +set ylabel "1/nu, Па^{-1}с^{-1}" +fit f1(x) 'plot_nut.plot' using 1:2:3 yerr via a1, b1 +plot 'plot_nut.plot' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2,\ + 'plot_nut.plot' notitle with lines lc rgb "blue" lw 1,\ + f1(x) title "Линейное приближение" lw 1 lc rgb "red" + diff --git a/libprakpp/include/prakcommon.hpp b/libprakpp/include/prakcommon.hpp index c9bced3..47c793c 100644 --- a/libprakpp/include/prakcommon.hpp +++ b/libprakpp/include/prakcommon.hpp @@ -75,24 +75,6 @@ fequal(T x, T y, std::size_t ulps = 1) return std::fabs(x - y) <= ulps * std::ldexp(std::numeric_limits<T>::epsilon(), exp); } -template<typename T> -T sum(const std::vector<T> &args) { - T res{}; - for (const T& x : args) res += x; - return res; -} - -template<typename T> -T prod(const std::vector<T> &args) { - T res = 1; - for (const T& x : args) res *= x; - return res; -} - -template <std::floating_point T> -T hypot(const std::vector<T> &args) { - return std::sqrt(args[0]*args[0] + args[1]*args[1]); -} /// prints a vector template <typename T> @@ -124,16 +106,17 @@ using vector = std::vector<T, align_alloc<T>>; /// prak value / pair value: a value with an error template <typename T> struct pvalue { T val, err; }; - -template <typename T> -struct pvalue<T> operator*(const struct pvalue<T> &v, T a) { - return pvalue<T>{v.val * a, v.err * a}; -} - -template <typename T> -std::ostream &operator<<(std::ostream &os, const struct pvalue<T> &p) { - /* return os << "value {" << p.val << "±" << p.err << "}"; */ - return os << p.val << "±" << p.err; -} +template <typename T> struct pvalue<T> operator*(const struct pvalue<T> &v, const T &a) { return {v.val * a, v.err * a}; } +template <typename T> struct pvalue<T> operator*(const T &a, const struct pvalue<T> &v) { return {v.val * a, v.err * a}; } +template <typename T> struct pvalue<T> operator*(const struct pvalue<T> &a, const struct pvalue<T> &b) { return {a.val * b.val, a.val * b.val * std::hypot(a.err/a.val, b.err/b.val)}; } +template <typename T> struct pvalue<T> operator/(const struct pvalue<T> &v, const T &a) { return {v.val / a, v.err / a}; } +template <typename T> struct pvalue<T> operator/(const struct pvalue<T> &a, const struct pvalue<T> &b) { return {a.val / b.val, a.val / b.val * std::hypot(a.err/a.val, b.err/b.val)}; } +template <typename T> struct pvalue<T> operator+(const struct pvalue<T> &a, const struct pvalue<T> &b) { return {a.val + b.val, std::hypot(a.err, b.err)}; } +template <typename T> struct pvalue<T> operator-(const struct pvalue<T> &a, const struct pvalue<T> &b) { return {a.val - b.val, std::hypot(a.err, b.err)}; } +template <typename T> struct pvalue<T> operator+(const struct pvalue<T> &a, const T &b) { return {a.val + b, a.err}; } +template <typename T> struct pvalue<T> operator-(const struct pvalue<T> &a, const T &b) { return {a.val - b, a.err}; } +template <typename T> struct pvalue<T> operator+(const T &a, const struct pvalue<T> &b) { return {a + b.val, b.err}; } +template <typename T> struct pvalue<T> operator-(const T &a, const struct pvalue<T> &b) { return {a - b.val, b.err}; } +template <typename T> std::ostream &operator<<(std::ostream &os, const struct pvalue<T> &p) { return os << p.val << "±" << p.err; } } // namespace prak diff --git a/libprakpp/include/prakmath.hpp b/libprakpp/include/prakmath.hpp index 54b902d..ebd02bf 100644 --- a/libprakpp/include/prakmath.hpp +++ b/libprakpp/include/prakmath.hpp @@ -4,6 +4,7 @@ #include <concepts> #include <iomanip> #include <numeric> +#include <functional> #ifdef __x86_64__ #include <immintrin.h> @@ -186,6 +187,45 @@ scalar: return linear + finalize(buf); } + +template<arithmetic T> +T sum(const std::vector<T> &args) { + T res{}; + for (const T& x : args) res += x; + return res; +} +template<std::floating_point T> +T prod(const std::vector<T> &args) { + T res = 1; + for (const T& x : args) res *= x; + return res; +} +template <std::floating_point T> +T hypot(const std::vector<T> &args) { + return std::sqrt(args[0]*args[0] + args[1]*args[1]); +} +template <arithmetic T, class op> +struct generic_arith { + T operator()(const std::vector<T> &args) { + return std::accumulate(args.cbegin(), args.cend(), T{}, op{}); + } +}; +template <arithmetic T> +struct plus: public generic_arith<T, std::plus<T>>{}; +template <arithmetic T> +struct minus: public generic_arith<T, std::minus<T>>{}; +template <arithmetic T> +T diff(const std::vector<T> &args) { return std::abs(args[0] - args[1]); } +template <arithmetic T> +T quot(const std::vector<T> &args) { return args[0] / args[1]; } +template <arithmetic T> T log(const std::vector<T> &arg){ return std::log(arg[0]); } +template <std::floating_point T> T inv(const std::vector<T> &arg){ return 1/arg[0]; } +template <typename T, T val> T add(const std::vector<T> &arg) { return val + arg[0]; } +template <typename T, T val> T sub(const std::vector<T> &arg) { return arg[0] - val; } +template <arithmetic T, T val> T mul(const std::vector<T> &arg) {return arg[0] * val; } +template <arithmetic T, T val> T div(const std::vector<T> &arg) {return arg[0] / val; } + + template <arithmetic T> T avg(const std::vector<T> &args) { T init{}; @@ -195,6 +235,8 @@ T avg(const std::vector<T> &args) { return init / args.size(); } +// Actually calculates not the standard deviation, but standard +// deviation OF the mean. This means additionally dividing by \sqrt{N-1} template <arithmetic T> T stddev(const std::vector<T> &args) { T sum = {}; diff --git a/libprakpp/include/prakphys.hpp b/libprakpp/include/prakphys.hpp new file mode 100644 index 0000000..1eaef5a --- /dev/null +++ b/libprakpp/include/prakphys.hpp @@ -0,0 +1,28 @@ +#pragma once + + + +#define TP template <typename T = double> constexpr const T + +namespace conv { +TP C_to_K = 273.15; // Celsius-Kelvin +TP K_to_C = -273.15; +TP J_to_eV = 6.2415e+18; +TP eV_to_J = 1 / 6.2415e+18; +} // namespace conv + +namespace prak { +TP g = 9.81; +TP c = 299792458; +TP h = 6.62607015e-34; +TP hh = 1.054571817e-34; +TP k = 1.380649e-23; +TP G = 6.67430151515e-11; +TP e = 1.602176634e-19; +TP m_e = 1.6021766342828e-31; +TP m_p = 1.672621925955252e-27; +TP m_n = 1.674927500568585e-27; +TP R = 8.31446261815324; +TP N_A = 6.02214076e23; + +} // namespace prak diff --git a/tempalte/plots.gp b/tempalte/plots.gp index 314be12..a6e5cbb 100644 --- a/tempalte/plots.gp +++ b/tempalte/plots.gp @@ -1,4 +1,5 @@ set term pngcairo size 1000, 800 +set grid #f1(x) = a1*x+b1 #fit f1(x) '.plot' using 1:2:3 yerr via a1, b1 diff --git a/vtek7/main.cpp b/vtek7/main.cpp index b5d4318..8796779 100644 --- a/vtek7/main.cpp +++ b/vtek7/main.cpp @@ -27,10 +27,10 @@ f64 U_err_MS8040(vecarg a) { } f64 I_err_MS8040(vecarg a) { f64 i = a[0]; - if (i < 2e-4) return i * 0.0015 + 15e-8; - if (i < 2e-3) return i * 0.0015 + 15e-7; - if (i < 2e-2) return i * 0.0015 + 15e-6; - return i * 0.0015 + 15e-5; + if (i < 2e-4) return i * 0.0015 + 1.5e-7; + if (i < 2e-3) return i * 0.0015 + 1.5e-6; + if (i < 2e-2) return i * 0.0015 + 1.5e-5; + return i * 0.005 + 15e-5; } f64 U_err_DT320B(vecarg a) { f64 u = a[0]; diff --git a/vtek7/plots.gp b/vtek7/plots.gp index 0f38281..fcc1567 100644 --- a/vtek7/plots.gp +++ b/vtek7/plots.gp @@ -1,4 +1,5 @@ set term pngcairo size 1000, 800 +set grid lw 2 f1(x) = a1 * x + b1 fit f1(x) 'ex1_EL.plot' yerr via a1, b1 @@ -42,6 +43,7 @@ plot 'ex1_EL.plot' using 1:2:3 with yerrorbars notitle lc 0 pt 1 lw 2, \ reset +set grid lw 2 set output 'ex2.png' set title "Зависимосьть I, U фотоида от освещённости E" @@ -59,6 +61,7 @@ plot 'ex2_IE.plot' axis x1y2 with lines title "I(E)",\ f21(x) axis x1y2 lt 10 notitle, f22(x) axis x1y1 lt 10 notitle reset +set grid lw 2 set output 'ex3.png' set term pngcairo size 1272, 900 @@ -86,6 +89,8 @@ set xrange[0:0.5] replot reset +set grid lw 2 + set term pngcairo size 1000, 800 set output 'ex4.png' @@ -105,6 +110,7 @@ plot 'ex4_UE.plot' axis x1y1 with lines title "U(E)",\ f41(x) lt 10 notitle , f42(x) axis x1y2 lt 10 notitle reset +set grid lw 2 set output 'ex6_1.png' set title "ВАХ Солнечной батареи" |