lundi 20 avril 2015

SyntaxError: can't assign to function call for a random walk

im trying to do a random walk using spyder

where theres 10,000 time steps , with a random no. between 0 and 1, if that no. is < 0.5 move left, > 0.5 move right

heres my code (# is for the spyder to ignore)

dx=1 #length of space step
t=0 #length of time step
N=10000 #number of particls
pos=zeros(1,N) #all particles start at x=0
T=t*N #end time

while t<=T: #do something until a specific condition is met
    p=uniform(0,1) #1xN array of random numbers between 0 and 1
    for i in range(1,N):
        if p(i) < 0.5:
            pos(i)=pos(i-1)-dx  #particle moves left
        elif p(i) > 0.5:
            pos(i)=pos(i-1)+dx  #particle moves right

print(pos(i))   

any help appreciated thanks




Aucun commentaire:

Enregistrer un commentaire