-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab1_1_add_task.py
65 lines (56 loc) · 1.1 KB
/
lab1_1_add_task.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import random
import math
import matplotlib.pyplot as plt
n = 10
omegaMax = 1200
N = 64
x = []
y = []
a = []
b = []
Dx = 0
Mx = 0
def Plot():
A = []
fi = []
for i in range(n):
A.append(random.random())
fii = random.random() * omegaMax
fi.append(fii)
for i in range(N):
res = 0
for j in range(n):
res += A[j] * math.sin((omegaMax / (j + 1)) * i + fi[j])
x.append(res)
yy = i
y.append(yy)
def Expectancy():
Mxx = 0
for t in range(N):
Mxx += (1 / N) * x[t]
return Mxx
def Dispersion():
Dx = 0
for t in range(N):
Dx += (1 / (N - 1)) * (x[t] - Mx) * (x[t] - Mx)
return Dx
#additional task
def Plott():
Dx = 0
for l in range(N):
aa = l
a.append(aa)
for t in range(N):
Dx += (1 / (N - 1)) * (x[t] - Mx) * (x[t] - Mx)
bb = Dx
b.append(bb)
if __name__ == "__main__":
Plot()
Plott()
print(Expectancy())
print(Dispersion())
#plt.plot(y, x)
plt.ylabel('N')
plt.xlabel('Dispersion')
plt.plot(b, a)
plt.show()