upd
This commit is contained in:
54
archive/sem3/labs_done/lab3.01_done/scripts/1.py
Normal file
54
archive/sem3/labs_done/lab3.01_done/scripts/1.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from sys import argv
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
|
||||
def read_points(filename: str) -> list[tuple[float, float, str]]:
|
||||
points = []
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and not line.startswith("#"):
|
||||
parts = line.split()
|
||||
if len(parts) >= 3:
|
||||
x = float(parts[0])
|
||||
y = float(parts[1])
|
||||
label = parts[2]
|
||||
points.append((x, y, label))
|
||||
return points
|
||||
|
||||
|
||||
def main() -> None:
|
||||
points = read_points(argv[1])
|
||||
|
||||
plt.figure(figsize=(8.27, 11.69))
|
||||
plt.xlim(0, 30)
|
||||
plt.ylim(0, 20)
|
||||
plt.gca().set_aspect("equal", adjustable="box")
|
||||
plt.grid(True, linewidth=0.3)
|
||||
plt.xticks(range(0, 31, 2))
|
||||
plt.yticks(range(0, 21, 2))
|
||||
|
||||
for x, y, label in points:
|
||||
plt.scatter(x, y, color="red", s=15)
|
||||
plt.text(x + 0.3, y + 0.3, label, fontsize=9)
|
||||
|
||||
if int(argv[2]):
|
||||
theta = np.linspace(0, 2 * np.pi, 200)
|
||||
cx, cy = 15, 9
|
||||
|
||||
for r in [5, 6]:
|
||||
x = cx + r * np.cos(theta)
|
||||
y = cy + r * np.sin(theta)
|
||||
plt.plot(x, y, color="blue", linewidth=1)
|
||||
|
||||
plt.xlabel("X (см)")
|
||||
plt.ylabel("Y (см)")
|
||||
plt.title("Эквипотенциальные точки")
|
||||
plt.tight_layout()
|
||||
plt.savefig("points.png", dpi=300)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
63
archive/sem3/labs_done/lab3.01_done/scripts/2.py
Normal file
63
archive/sem3/labs_done/lab3.01_done/scripts/2.py
Normal file
@@ -0,0 +1,63 @@
|
||||
from collections import defaultdict
|
||||
from sys import argv
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
|
||||
def read_points(filename: str) -> list[tuple[float, float, str]]:
|
||||
points = []
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and not line.startswith("#"):
|
||||
parts = line.split()
|
||||
if len(parts) >= 3:
|
||||
x = float(parts[0])
|
||||
y = float(parts[1])
|
||||
label = parts[2]
|
||||
points.append((x, y, label))
|
||||
return points
|
||||
|
||||
|
||||
def main() -> None:
|
||||
points = read_points(argv[1])
|
||||
|
||||
plt.figure(figsize=(8.27, 11.69))
|
||||
plt.xlim(0, 30)
|
||||
plt.ylim(0, 20)
|
||||
plt.gca().set_aspect("equal", adjustable="box")
|
||||
plt.grid(True, linewidth=0.3)
|
||||
plt.xticks(range(0, 31, 2))
|
||||
plt.yticks(range(0, 21, 2))
|
||||
|
||||
grouped = defaultdict(list)
|
||||
for x, y, phi in points:
|
||||
grouped[phi].append((x, y))
|
||||
|
||||
for x, y, label in points:
|
||||
plt.scatter(x, y, color="red", s=15)
|
||||
plt.text(x + 0.3, y + 0.3, label, fontsize=9)
|
||||
|
||||
for phi, coords in grouped.items():
|
||||
coords.sort(key=lambda p: p[1])
|
||||
xs, ys = zip(*coords)
|
||||
plt.plot(xs, ys, linewidth=0.8, label=f"φ={phi} В")
|
||||
|
||||
if int(argv[2]):
|
||||
theta = np.linspace(0, 2 * np.pi, 200)
|
||||
cx, cy = 15, 9
|
||||
|
||||
for r in [5, 6]:
|
||||
x = cx + r * np.cos(theta)
|
||||
y = cy + r * np.sin(theta)
|
||||
plt.plot(x, y, color="blue", linewidth=1)
|
||||
|
||||
plt.xlabel("X (см)")
|
||||
plt.ylabel("Y (см)")
|
||||
plt.title("Эквипотенциальные линии")
|
||||
plt.savefig("points.png", dpi=300)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
94
archive/sem3/labs_done/lab3.01_done/scripts/3.py
Normal file
94
archive/sem3/labs_done/lab3.01_done/scripts/3.py
Normal file
@@ -0,0 +1,94 @@
|
||||
from collections import defaultdict
|
||||
from sys import argv
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
|
||||
def read_points(filename: str) -> list[tuple[float, float, str]]:
|
||||
points = []
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and not line.startswith("#"):
|
||||
parts = line.split()
|
||||
if len(parts) >= 3:
|
||||
x = float(parts[0])
|
||||
y = float(parts[1])
|
||||
label = parts[2]
|
||||
points.append((x, y, label))
|
||||
return points
|
||||
|
||||
|
||||
def main() -> None:
|
||||
points = read_points(argv[1])
|
||||
|
||||
plt.figure(figsize=(8.27, 11.69))
|
||||
plt.xlim(0, 30)
|
||||
plt.ylim(0, 20)
|
||||
plt.gca().set_aspect("equal", adjustable="box")
|
||||
plt.grid(True, linewidth=0.3)
|
||||
plt.xticks(range(0, 31, 2))
|
||||
plt.yticks(range(0, 21, 2))
|
||||
|
||||
grouped = defaultdict(list)
|
||||
for x, y, phi in points:
|
||||
grouped[phi].append((x, y))
|
||||
|
||||
for x, y, label in points:
|
||||
plt.scatter(x, y, color="red", s=15)
|
||||
plt.text(x + 0.3, y + 0.3, label, fontsize=9)
|
||||
|
||||
for phi, coords in grouped.items():
|
||||
coords.sort(key=lambda p: p[1])
|
||||
xs, ys = zip(*coords)
|
||||
plt.plot(xs, ys, linewidth=0.8, label=f"φ={phi} В")
|
||||
|
||||
for i in range(len(coords) - 1):
|
||||
x1, y1 = coords[i]
|
||||
x2, y2 = coords[i + 1]
|
||||
|
||||
mid_x = (x1 + x2) / 2
|
||||
mid_y = (y1 + y2) / 2
|
||||
|
||||
dx = x2 - x1
|
||||
dy = y2 - y1
|
||||
|
||||
perp_dx = -dy
|
||||
perp_dy = dx
|
||||
|
||||
length = np.sqrt(perp_dx**2 + perp_dy**2)
|
||||
if length > 0:
|
||||
arrow_length = 0.5
|
||||
perp_dx = perp_dx / length * arrow_length
|
||||
perp_dy = perp_dy / length * arrow_length
|
||||
|
||||
plt.arrow(
|
||||
mid_x,
|
||||
mid_y,
|
||||
perp_dx,
|
||||
perp_dy,
|
||||
head_width=0.2,
|
||||
head_length=0.15,
|
||||
fc="green",
|
||||
ec="green",
|
||||
linewidth=1.5,
|
||||
)
|
||||
|
||||
if int(argv[2]):
|
||||
theta = np.linspace(0, 2 * np.pi, 200)
|
||||
cx, cy = 15, 9
|
||||
|
||||
for r in [5, 6]:
|
||||
x = cx + r * np.cos(theta)
|
||||
y = cy + r * np.sin(theta)
|
||||
plt.plot(x, y, color="blue", linewidth=1)
|
||||
|
||||
plt.xlabel("X (см)")
|
||||
plt.ylabel("Y (см)")
|
||||
plt.title("Эквипотенциальные линии с силовыми стрелками")
|
||||
plt.savefig("points.png", dpi=300)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
92
archive/sem3/labs_done/lab3.01_done/scripts/4.py
Normal file
92
archive/sem3/labs_done/lab3.01_done/scripts/4.py
Normal file
@@ -0,0 +1,92 @@
|
||||
from collections import defaultdict
|
||||
from sys import argv
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
|
||||
def read_points(filename: str) -> list[tuple[float, float, str]]:
|
||||
points = []
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and not line.startswith("#"):
|
||||
parts = line.split()
|
||||
if len(parts) >= 3:
|
||||
x = float(parts[0])
|
||||
y = float(parts[1])
|
||||
label = parts[2]
|
||||
points.append((x, y, label))
|
||||
return points
|
||||
|
||||
|
||||
def main() -> None:
|
||||
points = read_points(argv[1])
|
||||
|
||||
plt.figure(figsize=(8.27, 11.69))
|
||||
plt.xlim(0, 30)
|
||||
plt.ylim(0, 20)
|
||||
plt.gca().set_aspect("equal", adjustable="box")
|
||||
plt.grid(True, linewidth=0.3)
|
||||
plt.xticks(range(0, 31, 2))
|
||||
plt.yticks(range(0, 21, 2))
|
||||
|
||||
grouped = defaultdict(list)
|
||||
for x, y, phi in points:
|
||||
grouped[phi].append((x, y))
|
||||
|
||||
for x, y, label in points:
|
||||
plt.scatter(x, y, color="red", s=15)
|
||||
plt.text(x + 0.3, y + 0.3, label, fontsize=9)
|
||||
|
||||
for phi, coords in grouped.items():
|
||||
coords.sort(key=lambda p: p[1])
|
||||
xs, ys = zip(*coords)
|
||||
plt.plot(xs, ys, linewidth=0.8, label=f"φ={phi} В")
|
||||
|
||||
if int(argv[2]):
|
||||
theta = np.linspace(0, 2 * np.pi, 200)
|
||||
cx, cy = 15, 9
|
||||
|
||||
for r in [5, 6]:
|
||||
x = cx + r * np.cos(theta)
|
||||
y = cy + r * np.sin(theta)
|
||||
plt.plot(x, y, color="blue", linewidth=1)
|
||||
|
||||
emax_x, emax_y = 22.4, 10
|
||||
emin_x, emin_y = 15, 9
|
||||
|
||||
plt.arrow(
|
||||
emax_x + 2,
|
||||
emax_y + 2,
|
||||
-1.5,
|
||||
-1.2,
|
||||
head_width=0.4,
|
||||
head_length=0.3,
|
||||
fc="darkgreen",
|
||||
ec="darkgreen",
|
||||
linewidth=2,
|
||||
)
|
||||
plt.text(emax_x + 2.3, emax_y + 2.3, "E_max", fontsize=11, color="darkgreen")
|
||||
|
||||
plt.arrow(
|
||||
emin_x - 3,
|
||||
emin_y + 3,
|
||||
1.5,
|
||||
-1.5,
|
||||
head_width=0.4,
|
||||
head_length=0.3,
|
||||
fc="darkgreen",
|
||||
ec="darkgreen",
|
||||
linewidth=2,
|
||||
)
|
||||
plt.text(emin_x - 4.2, emin_y + 3.2, "E_min", fontsize=11, color="darkgreen")
|
||||
|
||||
plt.xlabel("X (см)")
|
||||
plt.ylabel("Y (см)")
|
||||
plt.title("Эквипотенциальные линии")
|
||||
plt.savefig("points.png", dpi=300)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
55
archive/sem3/labs_done/lab3.01_done/scripts/5.py
Normal file
55
archive/sem3/labs_done/lab3.01_done/scripts/5.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from pathlib import Path
|
||||
from typing import List, Tuple
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def read_points(filename: str) -> List[Tuple[float, float, float]]:
|
||||
pts = []
|
||||
for line in Path(filename).read_text(encoding="utf-8").splitlines():
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
parts = line.split()
|
||||
if len(parts) < 3:
|
||||
continue
|
||||
x = float(parts[0])
|
||||
y = float(parts[1])
|
||||
phi = float(parts[2])
|
||||
pts.append((x, y, phi))
|
||||
return pts
|
||||
|
||||
|
||||
def phi_vs_x_at_y(
|
||||
points: List[Tuple[float, float, float]], y_target: float, tol: float = 1e-6
|
||||
):
|
||||
xs = []
|
||||
phis = []
|
||||
for x, y, phi in points:
|
||||
if abs(y - y_target) <= tol:
|
||||
xs.append(x)
|
||||
phis.append(phi)
|
||||
paired = sorted(zip(xs, phis), key=lambda p: p[0])
|
||||
if not paired:
|
||||
return [], []
|
||||
xs_sorted, phis_sorted = zip(*paired)
|
||||
return list(xs_sorted), list(phis_sorted)
|
||||
|
||||
|
||||
p1 = read_points("points1.txt")
|
||||
p2 = read_points("points2.txt")
|
||||
|
||||
x1, yphi1 = phi_vs_x_at_y(p1, 10.0)
|
||||
x2, yphi2 = phi_vs_x_at_y(p2, 10.0)
|
||||
|
||||
plt.figure(figsize=(10, 5))
|
||||
if x1:
|
||||
plt.plot(x1, yphi1, marker="o", linestyle="-", label="points1.txt (Y=10)")
|
||||
if x2:
|
||||
plt.plot(x2, yphi2, marker="s", linestyle="--", label="points2.txt (Y=10)")
|
||||
plt.xlabel("X (см)")
|
||||
plt.ylabel("φ (В)")
|
||||
plt.title("Зависимость φ = φ(X) при Y = 10 см")
|
||||
plt.grid(alpha=0.4)
|
||||
plt.legend()
|
||||
plt.savefig("phi_vs_x_Y10.png", dpi=300)
|
||||
31
archive/sem3/labs_done/lab3.01_done/scripts/points1.txt
Normal file
31
archive/sem3/labs_done/lab3.01_done/scripts/points1.txt
Normal file
@@ -0,0 +1,31 @@
|
||||
# X Y Label
|
||||
2 2 1.89
|
||||
2.5 6 1.89
|
||||
2.8 10 1.89
|
||||
2.7 14 1.89
|
||||
2.0 18 1.89
|
||||
6.8 2 3.89
|
||||
6.8 6 3.89
|
||||
7.0 10 3.89
|
||||
6.9 14 3.89
|
||||
7.2 18 3.89
|
||||
11.8 2 5.89
|
||||
12.2 6 5.89
|
||||
12.5 10 5.89
|
||||
12.8 14 5.89
|
||||
12.6 18 5.89
|
||||
16.7 2 7.89
|
||||
16.8 6 7.89
|
||||
16.5 10 7.89
|
||||
16.3 14 7.89
|
||||
16.3 18 7.89
|
||||
21.3 2 9.89
|
||||
21.3 6 9.89
|
||||
21.3 10 9.89
|
||||
21.1 14 9.89
|
||||
21.0 18 9.89
|
||||
26.1 2 11.89
|
||||
25.7 6 11.89
|
||||
25.6 10 11.89
|
||||
25.7 14 11.89
|
||||
26.0 18 11.89
|
||||
77
archive/sem3/labs_done/lab3.01_done/scripts/points2.txt
Normal file
77
archive/sem3/labs_done/lab3.01_done/scripts/points2.txt
Normal file
@@ -0,0 +1,77 @@
|
||||
# X Y Label
|
||||
# phi = 2.4
|
||||
2.0 2 2.4
|
||||
2.1 4 2.4
|
||||
2.6 6 2.4
|
||||
2.8 8 2.4
|
||||
3.0 10 2.4
|
||||
2.8 12 2.4
|
||||
3.1 14 2.4
|
||||
2.7 16 2.4
|
||||
2.8 18 2.4
|
||||
# phi = 3.4
|
||||
4.1 2 3.4
|
||||
4.0 4 3.4
|
||||
4.1 6 3.4
|
||||
4.0 8 3.4
|
||||
4.2 10 3.4
|
||||
4.2 12 3.4
|
||||
4.6 14 3.4
|
||||
4.5 16 3.4
|
||||
4.8 18 3.4
|
||||
# phi = 4.4
|
||||
6.1 2 4.4
|
||||
5.9 4 4.4
|
||||
5.9 6 4.4
|
||||
5.5 8 4.4
|
||||
5.8 10 4.4
|
||||
5.7 12 4.4
|
||||
6.3 14 4.4
|
||||
7.0 16 4.4
|
||||
7.5 18 4.4
|
||||
# phi = 5.4
|
||||
8.4 2 5.4
|
||||
7.8 4 5.4
|
||||
7.4 6 5.4
|
||||
7.2 8 5.4
|
||||
7.2 10 5.4
|
||||
7.7 12 5.4
|
||||
8.2 14 5.4
|
||||
9.8 18 5.4
|
||||
# phi = 6.4
|
||||
11.2 2 6.4
|
||||
9.0 6 6.4
|
||||
8.8 10 6.4
|
||||
11.0 14 6.4
|
||||
12.3 18 6.4
|
||||
# phi = 7.4
|
||||
16.0 2 7.4
|
||||
15.5 18 7.4
|
||||
# phi = 8.4
|
||||
19.8 2 8.4
|
||||
20.3 4 8.4
|
||||
21.3 6 8.4
|
||||
21.7 8 8.4
|
||||
21.8 10 8.4
|
||||
21.3 12 8.4
|
||||
20.7 14 8.4
|
||||
19.7 16 8.4
|
||||
18.0 18 8.4
|
||||
# phi = 9.4
|
||||
22.2 2 9.4
|
||||
22.8 6 9.4
|
||||
22.9 10 9.4
|
||||
22.5 14 9.4
|
||||
21.7 18 9.4
|
||||
# phi = 10.4
|
||||
24.5 2 10.4
|
||||
24.4 6 10.4
|
||||
24.6 10 10.4
|
||||
24.2 14 10.4
|
||||
23.9 18 10.4
|
||||
# phi = 11.4
|
||||
26.7 2 11.4
|
||||
26.2 6 11.4
|
||||
26.2 10 11.4
|
||||
26.0 14 11.4
|
||||
26.1 18 11.4
|
||||
Reference in New Issue
Block a user