# This is a code for 8.08 - 8.S421, 2nd recitation. # You will run simulations of a Brownian particle with spatially-varying temperature, # and compare the density to the theoretical expectation. # for installing required packages # using Pkg # Pkg.add("Plots") # Pkg.add("Random") # load packages using Plots using Random #### #### DEFINE YOUR TEMPERATURE FUNCTION AND ITS DERIVATIVE HERE T(x,L) = 2.0 + sin(2*π*x/L) Tp(x,L) = (2*π/L)*cos(2*π*x/L) #### # integrator for simulating a harmonic oscillator function runBrownianTofx!( tf, # duration of your simulation h, # time step alpha, # discretization seed, # seed for random number generator L, # length of system num_cells, # number of cells in your histogram num_record, # number of data to be recorded data_histogram # array for recording time ) # create random number generator rng = MersenneTwister(seed) x_now, x_next = 0, 0 #state variables #### #### You might want to define more quantities here sqrt2h = sqrt(2*h) halpha = h*alpha #### t = 0 # current time Delta_t = tf / num_record # sampling time gap record_index = 1 # current index of my recording fill!(data_histogram, 0) # initialize your histogram while t < tf + Delta_t # simulate until tf is reached, with a tiny margin to assure full recording #### WRITE YOUR EQUATIONS OF MOTION HERE x_next = x_now + sqrt2h * sqrt(T(x_now,L)) * randn(rng) + halpha * Tp(x_now,L) #### # implement periodic boundary conditions if x_next>=L x_next = x_next - L elseif x_next<0 x_next = x_next + L end x_now = x_next if t > record_index*Delta_t && record_index