add hw 7
This commit is contained in:
34
pracs/prac7/scripts/1.py
Normal file
34
pracs/prac7/scripts/1.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Значения случайной величины
|
||||
xi = [0, 1, 2, 3, 4]
|
||||
|
||||
# Вероятности
|
||||
P = [16 / 81, 32 / 81, 24 / 81, 8 / 81, 1 / 81]
|
||||
|
||||
# Функция распределения
|
||||
F = []
|
||||
cum = 0
|
||||
for p in P:
|
||||
cum += p
|
||||
F.append(cum)
|
||||
|
||||
plt.figure(figsize=(12, 5))
|
||||
|
||||
# График вероятностей
|
||||
plt.subplot(1, 2, 1)
|
||||
plt.bar(xi, P, color="skyblue")
|
||||
plt.xlabel("xi")
|
||||
plt.ylabel("P(xi)")
|
||||
plt.title("Ряд распределения")
|
||||
|
||||
# График функции распределения
|
||||
plt.subplot(1, 2, 2)
|
||||
plt.step(xi, F, where="post", color="orange")
|
||||
plt.scatter(xi, F, color="red")
|
||||
plt.xlabel("xi")
|
||||
plt.ylabel("F(xi)")
|
||||
plt.title("Функция распределения")
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig("1.png")
|
||||
Reference in New Issue
Block a user