add hw 7
This commit is contained in:
23
pracs/prac7/scripts/4.py
Normal file
23
pracs/prac7/scripts/4.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from math import exp, factorial
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
# Задача 4: распределение Пуассона
|
||||
lambda4 = 2
|
||||
xi4 = list(range(0, 11))
|
||||
P4 = [lambda4**k * exp(-lambda4) / factorial(k) for k in xi4]
|
||||
F4 = np.cumsum(P4)
|
||||
|
||||
plt.figure(figsize=(7, 5))
|
||||
plt.bar(xi4, P4, color="plum", alpha=0.7, label="Вероятности")
|
||||
plt.step(xi4, F4, where="post", color="orange", label="Функция распределения")
|
||||
plt.scatter(xi4, F4, color="red")
|
||||
plt.title("Задача 4: распределение Пуассона")
|
||||
plt.xlabel("xi")
|
||||
plt.ylabel("P / F")
|
||||
plt.xticks(xi4)
|
||||
plt.legend()
|
||||
plt.grid(axis="y", linestyle="--", alpha=0.6)
|
||||
plt.tight_layout()
|
||||
plt.savefig("4.png")
|
||||
Reference in New Issue
Block a user