Stimulation of brown motion, asked by a beginner

Animation: Brownian motion.
Write a function with the following declaration: brown2D(N). The function takes in a single input N, which is an integer specifying the number of points in the simulation. All the points should initially start at the origin (0,0). Plot all the points on a figure using ‘.’ markers, and set the axis to be square and have limits from -1 to 1 in both the x and y direction. To simulate Brownian motion of the points, write a 1000-iteration loop which will calculate a new x and y position for each point and will display these new positions as an animation. The new position of each point is obtained by adding a normally distributed random variable with a standard deviation of 0.005 to each x and y value (use randn; if you have 100 points, you need to add 100 distinct random values to the x values and 100 distinct random values to the y values). Each time that the new positions of all the points are calculated, plot them on the figure and pause for 0.01 seconds (it’s best to use set and the line object handle in order to update the xdata and ydata properties of the points, as mentioned in lecture).
What you will see is a simulation of diffusion, wherein the particles randomly move away from the center of the figure. For example, 100 points look like the figures below at the start, middle,
and end of the simulation:
Can anyone give me a solution for that? I do not know how to initialize like 100 points at (0,0). I just need solution for that. For the rest of the program, I will try to work it out by myself. I just stuck at the first place

 Accepted Answer

x = zeros(100,1);
y = zeros(100,1);
or if you prefer them both in a single array:
xy = zeros(100, 2);
You might be interested in my random walk demo, in case your search didn't uncover it so far. http://www.mathworks.com/matlabcentral/answers/38118#answer_47548

1 Comment

Yeah. I will check out your random walk demo later. Thanks for your answer!

Sign in to comment.

More Answers (1)

xypos = zeros(100,2);
then xypos(K,1) is the X for particle #K, and xypos(K,2) is the Y for particle #K

1 Comment

Thanks a lot! Always happy to see my question could be answered so quickly

Sign in to comment.

Categories

Asked:

DI
on 18 Dec 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!