遞推關(guān)系——酵母菌生長(zhǎng)模型
import matplotlib.pyplot as plt
time = [i for i in range(0,19)]
number = [9.6,18.3,29,47.2,71.1,119.1,174.6,257.3,\
350.7,441.0,513.3,559.7,594.8,629.4,640.8,\
651.1,655.9,659.6,661.8]
plt.title('Relationship between time and number')#創(chuàng)建標(biāo)題
plt.xlabel('time')#X軸標(biāo)簽
plt.ylabel('number')#Y軸標(biāo)簽
plt.plot(time,number)#畫圖
plt.show()#顯示
import numpy as np
pn = [9.6, 18.3, 29, 47.2, 71.1, 119.1, 174.6,\
257.3, 350.7, 441.0, 513.3, 559.7, 594.8, 629.4,\
640.8, 651.1, 655.9, 659.6]
deltap = [8.7, 10.7, 18.2, 23.9, 48, 55.5,\
82.7, 93.4, 90.3, 72.3, 46.4, 35.1, \
34.6, 11.4, 10.3, 4.8, 3.7, 2.2]
pn = np.array(pn)
factor = pn * (665-pn)
f = np.polyfit(factor, deltap, 1) #擬合函數(shù)(1次)
print(f)
預(yù)測(cè)曲線
import matplotlib.pyplot as plt
p0 = 9.6
p_list = []
for i in range(20):
p_list.append(p0)
p0 = 0.00081448*(665-p0)*p0+p0
plt.plot(p_list)
plt.show()
馬爾可夫鏈——選舉投票預(yù)測(cè)
import matplotlib.pyplot as plt
RLIST = [0.33333]
DLIST = [0.33333]
ILIST = [0.33333]
for i in range(40):
R = RLIST[i]*0.75+DLIST[i]*0.20+ILIST[i]*0.40
RLIST.append(R)
D = RLIST[i]*0.05+DLIST[i]*0.60+ILIST[i]*0.20
DLIST.append(D)
I = RLIST[i]*0.20+DLIST[i]*0.20+ILIST[i]*0.40
ILIST.append(I)
plt.plot(RLIST)
plt.plot(DLIST)
plt.plot(ILIST)
plt.xlabel('Time')
plt.ylabel('Voting percent')
plt.annotate('DemocraticParty',xy = (5,0.2))
plt.annotate('RepublicanParty',xy = (5,0.5))
plt.annotate('IndependentCandidate',xy = (5,0.25))
plt.show()
print(RLIST,DLIST,ILIST)