From 5e81acb1a514231dc704f8e19f1a4c6e06318135 Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Sat, 26 Oct 2024 20:03:08 +0300 Subject: Structurization + 120 and 117 prak --- 120/prak120.gp | 14 +++++++++ 120/prak120.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 120/prak120_0.data | 69 +++++++++++++++++++++++++++++++++++++++++++ 120/prak120_1.data | 69 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 238 insertions(+) create mode 100644 120/prak120.gp create mode 100644 120/prak120.py create mode 100644 120/prak120_0.data create mode 100644 120/prak120_1.data (limited to '120') diff --git a/120/prak120.gp b/120/prak120.gp new file mode 100644 index 0000000..aa0e72b --- /dev/null +++ b/120/prak120.gp @@ -0,0 +1,14 @@ +set term png +set output 'prak120.png' +set errorbars linecolor black linewidth 0.5 dashtype '.' +s(x) = a*x + b +c(x) = c*x + d +d(x) = e*x + f +fit s(x) 'output_120_сталь.data' using 1:2:3 via a,b +fit c(x) 'output_120_медь.data' using 1:2:3 via c,d +fit d(x) 'output_120_дюраль.data' using 1:2:3 via e,f +set xlabel "n грузов (ед.)" +set ylabel "Delta N(n) (мм)" +plot 'output_120_сталь.data' using 1:2:3 with yerrorbars pointtype 1 linecolor 0 notitle, s(x) title "Сталь" , \ + 'output_120_дюраль.data' using 1:2:3 with yerrorbars pointtype 1 linecolor 0 notitle, d(x) title "Дюраль", \ + 'output_120_медь.data' using 1:2:3 with yerrorbars pointtype 1 linecolor 0 notitle, c(x) title "Медь" diff --git a/120/prak120.py b/120/prak120.py new file mode 100644 index 0000000..396a049 --- /dev/null +++ b/120/prak120.py @@ -0,0 +1,86 @@ +import os, sys + +# HACKHACKHACKHACKHACKHACKHACKHACKHACKHACKHACKHACK +cwd = os.getcwd() +cwd = cwd.rstrip('/1234567890') # remove characters from string +sys.path.insert(0, cwd) +from praklib import * + +from math import sqrt +from random import randint + +PI = 3.141592657 # :))))))))))))))))) + +def E(m, g, l, a, D, A, b): + return (m * g * 4 * l * a) / (PI * D * D * A * b) + +def _E(m, g, l, a, D, dN, b): + return (m * g * 4 * l * a) / (PI * D * D * dN * b) + +def main(): + AVGDIAM = 0 + DEVDIAM = 1 + D_NS = 2 + STDDEV_NS = 3 + print("3 значения толщины для стали: ") + steel = [float(input()) for i in range(3)] + print("3 значения толщины для меди: ") + copper = [float(input()) for i in range(3)] + print("3 значения толщины для дюраля: ") + dural = [float(input()) for i in range(3)] + l = (0.95, 0.005) + a = (0.1065, 0.001) + b = (0.0400, 0.001) + m0 = (0.2127, 0.0003) + materials = { + "сталь": [avg(steel), stddev(steel)], + "медь": [avg(copper), stddev(copper)], + "дюраль": [avg(dural), stddev(dural)] + } + for i in materials.keys(): + print("Материал:", i) + d_ns = [] + nups = ndowns = [] + for j in range(10): + print(f"delta N_{j} (добавление грузов): ") + up = float(input()) + print(f"delta N_{j} (убирание грузов): ") + down = float(input()) + nups.append(up) + ndowns.append(down) + d_ns.append([j, (up + down) / 2]); + # формула: корень(сумма( (n_вверх - n_сред)^2 + (n_вниз - n_сред)^2 ) / (20*19) ) для каждого n = [0..10] + sigma_ns = sqrt( \ + sum(( (avg-u)**2 + (avg-d)**2 for u, d, (_, avg) in zip(nups, ndowns, d_ns) )) \ + / (2*len(nups)) / (2*len(nups)-1) \ + ); # не 1 в 1 как сказано в задании, но по факту лучше + materials[i].append(d_ns) + materials[i].append([sigma_ns for _ in range(len(d_ns))]) + with open(f"output_120_{i}.data", "w+") as file: + for (n, dn), s in zip(materials[i][D_NS], materials[i][STDDEV_NS]): + file.write(f"{n} {dn} {s}\n") # я не знаю, работает ли write с любым кол-вом аргументов и документация питона говно + + mnk_res = mnk(np.array([i[0] for i in d_ns], dtype=float), np.array([i[1] for i in d_ns], dtype=float), np.array(materials[i][STDDEV_NS])) + args = [m0[0], 9.807, l[0], a[0], materials[i][AVGDIAM], mnk_res['a'], b[0]] + sigmas = [m0[1], 0.01, l[1], a[1], materials[i][DEVDIAM], mnk_res['sa'], b[1]] + print('-' * 10, ' ', i.upper(), ' ', '-' * 10); + print(f"D = {materials[i][AVGDIAM]}") + print('\n'.join([f"delta_N_{i[0]}: {i[1]}" for i in d_ns])) + print(f"Погрешность N: {sigma_ns}") + print(f"результат МНК:\n\tA={mnk_res['a']}±{mnk_res['sa']}\n\tB={mnk_res['b']}±{mnk_res['sb']}") + print(f"E: E={E(*args)}±{sigma(E, args, sigmas)}") + index1 = randint(1, 9) + args[0] = m0[0] * d_ns[index1][0] + args[5] = d_ns[index1][1] + sigmas[0] = m0[1] * index1 + print(f"для i={index1}: E={_E(*args)}±{sigma(_E, args, sigmas)}") + index2 = index1 + while (index2 == index1): index2 = randint(1, 9); + args[0] = m0[0] * d_ns[index2][0] + args[5] = d_ns[index2][1] + sigmas[0] = m0[1] * index1 + print(f"для i={index2}: E={_E(*args)}±{sigma(_E, args, sigmas)}") + + +if __name__ == "__main__": + main() diff --git a/120/prak120_0.data b/120/prak120_0.data new file mode 100644 index 0000000..fe6c1a7 --- /dev/null +++ b/120/prak120_0.data @@ -0,0 +1,69 @@ +0.51 +0.505 +0.51 +1.085 +1.08 +1.08 +1.50 +1.59 +1.59 +0 +-0.05 +0.11 +0.06 +0.18 +0.165 +0.3 +0.39 +0.425 +0.42 +0.53 +0.53 +0.64 +0.65 +0.76 +0.76 +0.87 +0.85 +0.98 +0.98 +0 +0.39 +0.13 +0.5 +0.38 +0.62 +0.5 +0.72 +0.605 +0.82 +0.73 +0.91 +0.84 +1.00 +0.98 +1.08 +1.08 +1.17 +1.23 +1.23 +0 +0 +0.045 +0.05 +0.095 +0.09 +0.14 +0.14 +0.18 +0.18 +0.22 +0.23 +0.26 +0.28 +0.31 +0.32 +0.35 +0.35 +0.39 +0.39 diff --git a/120/prak120_1.data b/120/prak120_1.data new file mode 100644 index 0000000..b8558b1 --- /dev/null +++ b/120/prak120_1.data @@ -0,0 +1,69 @@ +0.51 +0.505 +0.51 +1.085 +1.08 +1.08 +1.50 +1.59 +1.59 +0 +-0.05 +0.11 +0.06 +0.18 +0.165 +0.3 +0.39 +0.425 +0.42 +0.53 +0.53 +0.64 +0.65 +0.76 +0.76 +0.87 +0.85 +0.98 +0.98 +0 +0.04 +0.1 +0.135 +0.19 +0.24 +0.29 +0.34 +0.38 +0.43 +0.47 +0.51 +0.55 +0.6 +0.64 +0.66 +0.705 +0.74 +0.78 +0.78 +0 +0 +0.045 +0.05 +0.095 +0.09 +0.14 +0.14 +0.18 +0.18 +0.22 +0.23 +0.26 +0.28 +0.31 +0.32 +0.35 +0.35 +0.39 +0.39 -- cgit v1.2.3-70-g09d2