How to simulate brownian motion using for loops?

조회 수: 14 (최근 30일)
EliS
EliS 2016년 9월 27일
댓글: Image Analyst 2021년 4월 20일
This is what I am supposed to do, I have no idea where and how to start and do this, even though I understand how to use for-loops and understand what I am supposed to do.
" Part 1. Write a Matlab program that simulates and visualizes N number of particles Brownian motion. When the program works as it should, you will see a simulation of a diffusion process on screen. Let all N = 100 particles start at the origin, (0, 0). To simulate the random movement of the particles, write a for loop with M = 5,000 steps (iterations) with new values for the particles position (x, y), calculated in each step. We can imagine that each step is a small unit of time, say 1 second. The new positions will get by adding (Gaussian) random numbers to the old positions, multiplied by the coefficient (sigma), σ = sqrt(4D / π). D is the diffusion constant. Select eg D = 0.0001. In Matlab the randn function gives normally distributed random numbers. If x and y are vectors containing coordinates of all the particles, then the following lines x = x + sigma * randn (size (x)); y = y + sigma * randn (size (y)); give the random change of the positions. sigma given by the above expression. Each time a new position has been calculated for the N particles, you plot them in a figure in which the particle's current position is marked with a star (write plot (x, y, '*')). Fix the axes of plot between -1 and 1, with the command axis ([- 1 1 -1 1]). To ensure that you get to see something on screen print pause (0.01) after the plot statement in the for loop. Then the program stops in time=0:01's before it goes on. (Note that you must plot the particles current position at any time, not the particles paths.)
Part 2. Expand your application so that it also calculates the mean particle distance to the origin of each iteration. For each iteration, the intermediate distance is saved in a vector. The average distance you get if you add up all individual particles distance and assign the result to the number of particles. At the end of the program you plot the average distance as a function of the number of iterations (= time). On the Wikipedia page on Brownian motion we read that Einstein showed that the average distance, s, a particle moved during a certain time, t, in a liquid or gas with a diffusion constant D is given by sqrt(2DT). Graph s versus t in the same plot as the above.
Part 3. Use your program and making a calculation with 1000 particles."

답변 (2개)

Image Analyst
Image Analyst 2016년 9월 27일
In the meantime, attached are some random walk programs that I wrote, that all do slightly different things, that you can adapt. It should be enough to get you started.

Gautam Jha
Gautam Jha 2021년 4월 20일
Hy i am simulating the Thermoacoustic phenomena, where i need to add the noise term which then converted to stocashtic Differential equation, i have my .m file where i have written my code & now i would like to modify that for stochastic process ?
  댓글 수: 1
Image Analyst
Image Analyst 2021년 4월 20일
Maybe start your own question and attach your m-file with the paperclip icon.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by