MEDIA > PROGRAMMING > BROWNIAN MOTION SIMULATION


Download the Maple source here and follow along. Do not copy from this page and paste into Maple, it might not work right that way.

So imagine for a moment, if you will, a fantasy world in which one of your physics professors tells you to do a project on Brownian Motion.

"But Dr. <insert favorite professor name here>, what are the guidelines of this project? Is it a report? I need direction."
(S)He replies with, "Surprise me. Just show me that you know a thing or two about it."

So that settles it, you're going to study Brownian Motion using Maple. And you know what? You're going to write a short summarizing paper that describes what you've found. This wont be any typical paper though, no sir (or ma'am). This paper is going to be the most well-formatted, professional, and sexy scientific paper that your professor has ever seen from a student. Let's see how it's done!

First, a little background about Brownian Motion. It's a pretty simple concept. Brownian Motion (Wikipedia article here) is the random movement of small particles suspended in a liquid or gas. The reason this movement happens is because the particle is always being bombarded by the liquid or gas particles on all sides. Every now and then though, it gets hit by more particles on one side than the other, by chance. The result is that the particle moves away from the side of heavier bombardment. So let's write a model with maple that simulates this! Aren't you excited? I sure am.

For our example, we'll say that a container filled with water is 10m x 10m x 10m in volume. We'll call the exact center of the container the origin (0,0,0), so that means that each side of the container stretches from -5 to 5, as far as coordinates go.
The first thing we need to do is define our initial coordinate. The particle will start at (0,0,0). Here is how we define the position as (0,0,0):

position := [ 0,0,0 ] ;
coords := position ;

With the above code, I've defined two things. position is the current position. coords is a list of every position. As of right now, they're the same, but once we run the program, the coords list will grow, and the position will change, but stay the same size.
So right now I have the first position. I need to now determine my second position. The second position has to be random though. Maple has a random number generator built into it, the command for that is below. You have to use the with(RandomTools): command before generating random numbers otherwise Maple will get confused because it's silly. So the code below generates 2 random numbers between 1 and 100 and stores them as random1 and random2. We will use these random numbers to determine a random direction for the particle to move in. We find these directions by multiplying the random numbers by 2 pi, so that they're in radians. So now we have two angles, theta and phi. theta is the angle made with the positive x and y axes, and phi is the angle made with the xy-plane and the positive z axis.

with(RandomTools) :
random1 := RandomTools[Generate](float(range=1..100) ) :
random2 := RandomTools[Generate](float(range=1..100) ) :
theta := 2 * Pi * random1( ) ;
phi := 2 * Pi * random2( ) ;

The above code generates an output similar to the following:

θ = 79.68335678 π
Φ = 111.5899054 π


You've made it this far; go on to Page 2 --->