無(wú)標(biāo)題文章

import random

import numpy as np

import matplotlib.pyplot as plt

import math

def randpath(tt):

b=[]

bb=[]

b.append(0)

bb.append(0)

b2=[]

for i in range(tt):

c=random.random()

bb.append(i+1)

b.append(b[-1]-1+2*c)

for j in range(len(b)):

b2.append(b[j])

return b,bb,b2

a,b,c=randpath(1000)

a1,b1,c1=randpath(1000)

for k in range(len(b)):

plt.scatter([b[k],],[c[k],], 7, color ='red')

plt.scatter([b1[k],],[c1[k],], 7, color ='blue')

plt.xlim(0,1000)

plt.xlabel('time/step number')

plt.ylabel('X')

plt.title('random walk in one dimesion')

plt.show()

"""

c22=[]

c11=[0]*101

for i in range(100000):

a1,b1,c1=randpath(100)

for j in range(len(a1)):

c11[j]=c11[j]+c1[j]/100000.0

for k in range(len(b1)):

plt.scatter([b1[k],],[c11[k],],7,color='blue')

plt.scatter([b1[k],],[a1[k],], 3, color ='orange')

print len(b1),len(c11),len(a1)

z1=np.polyfit(b1, c11,1)

for i in range(len(b1)):

c22.append(z1[0]*b1[i]+z1[1])

plt.plot(b1,c22,color='red',label='y=0.3354*x+0.0102')

plt.xlim(0,100)

plt.ylim(0,)

plt.xlabel('time/step number')

plt.ylabel('the average square distance')

plt.title('random walk in one dimesion')

plt.legend(loc='upper left', frameon=True)

print z1

plt.show()

"""

Contact GitHub
API
Training
Shop
Blog
About

[

](https://github.com/)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容