代码1

作者: xuqiuhao | 来源:发表于2017-01-02 13:44 被阅读0次
    from __future__ import division
    import numpy as np
    import matplotlib.pyplot as plt
    
    steps = np.linspace(0, 100, 101)
    x_ave = np.zeros(101)
    x_y0 = np.zeros(101)
    x_now = np.zeros(500)
    
    for i in range(100):
        for j in range(500):
            ruler = np.random.rand()
            if ruler<=0.5:
                x_now[j] = x_now[j] + 1
            else:
                x_now[j] = x_now[j] - 1
        average = sum(x_now)/500
        x_ave[i+1] = average
        
    plt.scatter(steps, x_ave)
    plt.plot(steps, x_y0)
    plt.xlim(0,100)
    plt.ylim(-1,1)
    plt.grid(True)
    plt.xlabel('step number(= time)')
    plt.ylabel('<x>')
    plt.title('<x> of 500 walkers')
    
    plt.show()
    

    相关文章

      网友评论

          本文标题:代码1

          本文链接:https://www.haomeiwen.com/subject/qzywvttx.html