python - Plotting histogram of brownian motion? -
my task plot histogram of simulation of brownian motion. thankfully, i've made program simulates brownian motion, , plots on scatter plot function of time , distance. output looks like:

however, need convert histogram, 5 different locations (e.g: histogram @ t=0,1,2,3,4).
currently packages have numpy, mattplotlib, , scipy. have seen examples of how plot normal distribution, how plot distribution data have gathered?
here code have far: http://pastebin.com/aepqdqd2
(since couldn't post 2 links, had paste both files together, first 1 one computation brownian motion , second 1 outputs graph on imgur link)
this not homework, given credit problem, , instructor explicitly said allowed use whatever information can.
thanks.
use pylab.hist this, after calculating index of time point you're interested in, it:
# -*- coding: utf-8 -*- import numpy pylab import plot, xlabel, ylabel, title, grid, show, hist, legend brownian import brownian #this code performs main iteration of euler marayuma process, t=0 t=10. def main(): # wiener process parameter. delta = 2 # total time. t = 10.0 # number of steps. n = 500 # time step size dt = t/n # number of realizations generate. m = 1000 # create empty array store realizations. x = numpy.empty((m,n+1)) # initial values of x. x[:, 0] = 0 brownian(x[:,0], n, dt, delta, out=x[:,1:]) t = numpy.linspace(0.0, n*dt, n+1) # time points of interest ts = [4., 3., 2., 1.] t in ts: = int(t/t * n) hist(x[:, it], alpha=0.7, label='%.1f s' % t, normed=true) legend() show() if __name__ == "__main__": main() 
(you may care plot histograms on separate figures and/or make bin size constant across time points.)
Comments
Post a Comment