Random steps of molecules undergoing Brownian motion

2 次查看(过去 30 天)
I have an assignment were I have to develop a computer model that mimics the random steps of molecules undergoing Brownian motion. Using Matlab and the
following criteria:
• Tracks the motion of 300 molecules within a 2-D space, over a series of time steps
• On each time step every molecule will move by a random amount in the x and y directions
• Your model needs to calculate the steps in space for all 300 molecules, store them in an array and repeat this for 100 time steps
• Start the model with all molecules at the [0,0] point
• At each time point plot the position of the molecules in a scatter plot and run this for all time points so that a ‘movie’ of the molecular motion is created
I'm a novice when it comes to Matlab so any help is much appreciated

采纳的回答

Image Analyst
Image Analyst 2019-12-13
Basically you can construct arrays for x and y where the row represents that particle, and the column is the step number (time point). So
numParticles = 300;
numSteps = 100;
x = zeros(numParticles, numSteps);
y = zeros(numParticles, numSteps);
Now you need a for loop over the number of steps where you compute a new x and y for all 300 particles and then plot them.
for stepNumber = 2 : numSteps
% Make all 300 particles move to a new location.
for p = 1 : numParticles
x(p, stepNumber) = x(p, stepNumber - 1) + stuff you write.
% Same for y
% Now to make a movie, plot it and call drawnow and pause
plot(x(p, 1:stepNumber), y(p, 1:stepNumber), 'b-');
hold on;
end
hold off;
drawnow;
grid on;
pause(0.4) % Bigger numbers will pause longer and make for a slower movie.
end
Adapt as needed and fill out the rest, like deciding on the delta x and delta y to add. I prefer plot() since you can see the "history" of the path as it wanders around, but you can use scatter(x, y) like the directions told you to, though that won't let you see the history of the path. You can fancy it up with xlabel(), ylabel(), and title().
  1 个评论
Image Analyst
Image Analyst 2019-12-14
If I do that (finish the last two lines to complete, then what will you have done? Are you going to just turn in my code as your own for your assignment? Just use rand() to get your delta x and y and if you still can't figure out the last two lines then post what you have after you've read this link
I'm attaching a variety of random walk demos that I've done over the years.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by