-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp7.py
More file actions
41 lines (41 loc) · 1.1 KB
/
Copy pathp7.py
File metadata and controls
41 lines (41 loc) · 1.1 KB
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
import numpy as np
import matplotlib.pyplot as plt
p=[1, 0, 0, 0, 0]
u=1
step=100
pExact=0.8
pOvershoot=0.1
pUndershoot=0.1
entropy=np.zeros(step)
def move(p,u,pExact,pOvershoot,pUndershoot):
n=len(p)
q = np.zeros(n)
for i in range(1, n + 1):
l = i - 1
x, y = divmod(i - 1 - u, n)
q[l] = pExact * p[y]
x, y = divmod(i - 2 - u, n)
q[l] = q[l] + pOvershoot * p[y]
x, y = divmod(i - u, n)
q[l] = q[l] + pUndershoot * p[y]
return q
# q=move(p,u,pExact,pOvershoot,pUndershoot)
plt.ion()
for i in range(1,step+1):
p=move(p,u,pExact,pOvershoot,pUndershoot)
entropy[i-1]=-sum(p * np.log2(p))
print(i)
print(p)
# print(entropy)
# print(p)
# plt.cla()
# x=plt.xlim(1,step)
y = entropy
plt.plot(y,'r^',linewidth=0.5,markersize=6)#,shap='-',linewidth=2,color='g'
plt.plot(y,'g',linewidth=2,markersize=2)#,shap=':',linewidth=1.5,color='r'
# plt.xlim(1,step,10)
plt.xlabel('Motion step')
plt.ylabel('Entropy')
# plt.pause(0.5) #每次图表显示间隔的时间
plt.ioff()
plt.show()