- #1
Ante
- 3
- 0
I want to simulate molecular diffusion in MATLAB.
The idea is as follows:
http://www.math.chalmers.se/Math/Grundutb/GU/MVG300/V11/Laborationer/anim1.jpg
The picture represents a gas container and the red part is a barrier which the gas molecules cannot pass through except for the small area above it. The molecules are on the left side at the beginning, and moves RANDOMLY and we will animate this with sequences of pictures in a loop - and after one iteration the molecules position will uppdate.
After 1000 iterations:
http://www.math.chalmers.se/Math/Grundutb/GU/MVG300/V11/Laborationer/anim2.jpg
(x, y) is the initial position of the molecules and the new position is (x + dx, y + dy) where dx = randomnumber, dy = randomnumber.
The particles will hit the barrier and the containers wall, and we will simulate it as follows: If(x + dx, y + dy) is outside the container or within the barrier then we place the particle on the wall. ASay that (x + dx, y + dy) = (-0.21, 0.74).We let the particles position to be (0, 0.74) (analog in other cases).
When the naimation is done, a new window will open and in this the relative amount of particles on the left side will plot as a function of the iterations.
Something like this:
http://www.math.chalmers.se/Math/Grundutb/GU/MVG300/V11/Laborationer/anim3.jpg
Question:
How do I write a MATLAB program diff_anim with above ideas? diff_anim invokes with two parameters diff_anim(no_of_part, no_of_iterations). no_of_part is the amount of particles and no_of_iterations is thje amount of iterations. Particles initial position should randomly generate in the intervall 0 <= x <= 0.9, 0 <= y <= 1.
The idea is as follows:
http://www.math.chalmers.se/Math/Grundutb/GU/MVG300/V11/Laborationer/anim1.jpg
The picture represents a gas container and the red part is a barrier which the gas molecules cannot pass through except for the small area above it. The molecules are on the left side at the beginning, and moves RANDOMLY and we will animate this with sequences of pictures in a loop - and after one iteration the molecules position will uppdate.
After 1000 iterations:
http://www.math.chalmers.se/Math/Grundutb/GU/MVG300/V11/Laborationer/anim2.jpg
(x, y) is the initial position of the molecules and the new position is (x + dx, y + dy) where dx = randomnumber, dy = randomnumber.
The particles will hit the barrier and the containers wall, and we will simulate it as follows: If(x + dx, y + dy) is outside the container or within the barrier then we place the particle on the wall. ASay that (x + dx, y + dy) = (-0.21, 0.74).We let the particles position to be (0, 0.74) (analog in other cases).
When the naimation is done, a new window will open and in this the relative amount of particles on the left side will plot as a function of the iterations.
Something like this:
http://www.math.chalmers.se/Math/Grundutb/GU/MVG300/V11/Laborationer/anim3.jpg
Question:
How do I write a MATLAB program diff_anim with above ideas? diff_anim invokes with two parameters diff_anim(no_of_part, no_of_iterations). no_of_part is the amount of particles and no_of_iterations is thje amount of iterations. Particles initial position should randomly generate in the intervall 0 <= x <= 0.9, 0 <= y <= 1.