diff options
Diffstat (limited to '234')
-rw-r--r-- | 234/Makefile | 18 | ||||
-rw-r--r-- | 234/README.md | 5 | ||||
-rw-r--r-- | 234/compile_flags.txt | 4 | ||||
-rw-r--r-- | 234/data3 | 7 | ||||
l--------- | 234/include | 1 | ||||
-rw-r--r-- | 234/main.cpp | 76 | ||||
-rw-r--r-- | 234/plots.gp | 30 |
7 files changed, 141 insertions, 0 deletions
diff --git a/234/Makefile b/234/Makefile new file mode 100644 index 0000000..224506f --- /dev/null +++ b/234/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/234/README.md b/234/README.md new file mode 100644 index 0000000..96fd716 --- /dev/null +++ b/234/README.md @@ -0,0 +1,5 @@ +<!-- Шаблон для прака --> +<!-- файлы, заканчивающиеся на .plot считаются генерируемыми и удаляются через make clean --> +# Обработка <> прака + + diff --git a/234/compile_flags.txt b/234/compile_flags.txt new file mode 100644 index 0000000..34ae930 --- /dev/null +++ b/234/compile_flags.txt @@ -0,0 +1,4 @@ +-Iinclude +-std=c++2c +-mavx2 + diff --git a/234/data3 b/234/data3 new file mode 100644 index 0000000..3b9cb69 --- /dev/null +++ b/234/data3 @@ -0,0 +1,7 @@ +n s s2 sn t +0.3881 0.6102 ? ? 2 +1.97 1.411 ? ? 10 +3.834 1.885 ? ? 20 +7.802 2.738 ? ? 40 +16.08 3.8 ? ? 80 +31.71 5.75 ? ? 160 diff --git a/234/include b/234/include new file mode 120000 index 0000000..2225752 --- /dev/null +++ b/234/include @@ -0,0 +1 @@ +../libprakpp/include/
\ No newline at end of file diff --git a/234/main.cpp b/234/main.cpp new file mode 100644 index 0000000..6762d1c --- /dev/null +++ b/234/main.cpp @@ -0,0 +1,76 @@ +#include <iostream> + +#include "include/praktable.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> &; + +f64 factorial(u64 times) { + f64 res = 1; + for (; times; res *= times--); + return res; +} + +f64 poisson(u64 at, f64 avg) { + return std::pow(avg, at) * std::exp(-avg) / factorial(at); +} + +template <typename lambda, typename...Args> +f64 distr_sum(lambda f, u64 from, u64 to, Args...args) { + f64 res = 0; + for(; from <= to; res += f(from++, args...)); + return res; +} + +void ex1() { + f64 n = 1.053, s = 0.582553; + std::cout << "ex 1:\n" + var(distr_sum(poisson, n, n, n)) + var(distr_sum(poisson, n, n+1, n)) + var(distr_sum(poisson, std::round(n-s), std::round(n+s), n)) + var(distr_sum(poisson, std::round(n-2*s), std::round(n+2*s), n)) + << std::endl; +} +table ex3(const char* file) { + table t(file); + t .apply([](argvec a){return a[0]*a[0];}, "s", "s2") + .apply([](argvec a){return a[0]/a[1];}, std::vector<std::string>{"s", "n"}, "sn") + .write_plot("s(n).plot" , "n", "s", std::nullopt) + .write_plot("s2(n).plot", "n", "s2", std::nullopt) + .write_plot("sn(n).plot", "n", "sn", std::nullopt) + .print(); + return t; +} +void ex4(table t0) { + table t1({"count", "N", "n1", "s1", "n2", "s2", "s", "s/sn1", "s/sn2", "sqrtn1", "sqrtn2"}, 6, 0); + f64 T1 = 45e-3; + f64 T2 = 0.625; + for (int i = 0; i < 6; ++i) { + t1["count", i] = i+1; + t1["N", i] = t0["n", i] / t0["t", i] * 1000; + t1["s", i] = t0["s", i] / std::sqrt(t0["t", i] / 1000); + } + t1 .apply([T1](vecarg a){return a[0]*T1;}, "N", "n1") + .apply([T1](vecarg a){return a[0]*std::sqrt(T1);}, "s", "s1") + .apply([T2](vecarg a){return a[0]*T2;}, "N", "n2") + .apply([T2](vecarg a){return a[0]*std::sqrt(T2);}, "s", "s2"); + f64 avgn1 = t1.col_avg("n1"), + avgn2 = t1.col_avg("n2"), + savgn1 = t1.col_stddev("n1"), + savgn2 = t1.col_stddev("n2"); + t1 .apply([savgn1](vecarg a){return a[0]/savgn1;}, "s1", "s/sn1") + .apply([savgn2](vecarg a){return a[0]/savgn2;}, "s2", "s/sn2") + .apply([](vecarg a){return std::sqrt(a[0]);}, "n1", "sqrtn1") + .apply([](vecarg a){return std::sqrt(a[0]);}, "n2", "sqrtn2") + .print(); + std::cout var(avgn1)var(avgn2)var(savgn1)var(savgn2); +} + +int main() { + ex1(); + ex4(ex3("data3")); + return 0; +} diff --git a/234/plots.gp b/234/plots.gp new file mode 100644 index 0000000..a357dca --- /dev/null +++ b/234/plots.gp @@ -0,0 +1,30 @@ +set term pngcairo size 1000, 800 +set grid + +f1(x) = a1*sqrt(b1*x) +f2(x) = a2/(x-b2)+c2 +f3(x) = a3*x+b3 +fit f1(x) 's(n).plot' using 1:2 via a1, b1 +fit f2(x) 'sn(n).plot' using 1:2 via a2, b2, c2 +fit f3(x) 's2(n).plot' using 1:2 via a3, b3 + +set output 's(n).png' +set title "График зависимости дисперсии, стандартного отклонения и относительной флуктуации от среднего" +set y2tics +set xlabel "n, среднее" +set ylabel "s, s/n" +set y2label "s^2" +set key top lef +set yrange[0:7] +set y2range[0:35] + + +plot 's(n).plot' with lines title "s(n)" lc rgb('red') lw 2, \ + 'sn(n).plot' with lines title "s/n(n)" lc rgb('blue') lw 2, \ + 's2(n).plot' with lines title "s^2(n)" axes x1y2 lc rgb('green') lw 2, \ + 's(n).plot' lc 0 pt 2 lw 2 notitle,\ + 'sn(n).plot' lc 0 pt 2 lw 2 notitle,\ + 's2(n).plot' lc 0 pt 2 lw 2 axes x1y2 notitle,\ + f1(x) lc 0 lw 1 dashtype(20,10) notitle,\ + f2(x) lc 0 lw 1 dashtype(20,10) notitle,\ + f3(x) axes x1y2 notitle lc 0 lw 1 dashtype(20,10) |