-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp6.py
More file actions
38 lines (37 loc) · 999 Bytes
/
Copy pathp6.py
File metadata and controls
38 lines (37 loc) · 999 Bytes
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
import numpy as np
import matplotlib.pyplot as plt
p=[1, 0, 0, 0, 0]
u=1
step=20
pExact=0.8
pOvershoot=0.1
pUndershoot=0.1
# n=len(p)
# q = np.zeros(n)
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
fig1=plt.figure(figsize=(10,10),dpi=80)
plt.ion() #开启交互模式
# q=move(p,u,pExact,pOvershoot,pUndershoot)
for i in range(1,step+1):
print(i)
p=move(p,u,pExact,pOvershoot,pUndershoot)
print(p)
plt.cla()
plt.bar(x=(1,2,3,4,5),height=p)
plt.title('step=%s'%i)
plt.ylim(0,1)
plt.ylabel('Probability')
plt.pause(0.5)
plt.ioff()#关闭交互模式,如果不关闭图像就会一闪而过,不会长留
plt.show()