Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Brownian motion is a physical phenomenon which can be observed, for instance, wh

ID: 3557078 • Letter: B

Question

Brownian motion is a physical phenomenon which can be observed, for instance,

when a small particle is immersed in a liquid. One method for describing this motion (in one

-dimension) involves modelling the particles as "jumping" once per

microsecond a random distance. The Brownian model predicts how far the particle moves after

waiting a certain amount of time. Because the model is based onrandom numbers

, we are interested in the average distance the particle moves.

Write a program that will simulate Brownian motion by doing

ALL of the following:

1) Ask the user how many trials to run.

2) Run the requested number of trials. For each trial you will si

mulate the Brownian

motion of one particle over 10 microseconds (10 jumps). The particle should jump

up to 1 nanometer to the left or right with each

jump

.

3) Calculate the average

absolute value

of the distance that the particle has moved.

4) Print the

average absolute value of the distance to the screen.

Hints:

1) You will need rand() from <stdlib.h> to generate random numbers to simulate the

jum ping.

Note that rand() generates random integers, but for Brownian motion

the jumps must be floating point values.

2) The code is easiest if you consider negative numbers as movement to the left and

positive numbers as movement to the right. Then you can simulate a jump by

generating a random number between- 1 and 1. The position of the particle is simply the sum of all the jumps.

3) You can use abs() from <math.h> to take the absolute value of the

final

distance.

Do not

take the absolute value of each jump or you will lose the left/right

information.

4

) You will probably need two loops. One to loop thr

ough each trial, and one to loop

through each of the 10 jumps.

5

) Because we are taking the absolute value of the final distance, the average

displacement of the particles after 10 jumps should

not

be 0.

6

) Because the code is based on a random number

generator, you should get a

slightly different answer each time you run the code.

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define NUM_JUMPS 10

int main() {
   int trials;
   printf("Enter no. of trials : ");
   scanf("%d", &trials);
   int i,j;
   double total_avg_movement = 0;
   for(i=0; i<trials; ++i) {
       printf("Trial %d : ", i+1);
       double net_movement = 0;
       for(j=0; j<NUM_JUMPS; ++j) {
           double movement = (((double)(rand() % 10000)) / 5000) - 1;
           net_movement += movement;
       }
       double avg_movement = fabs(((double)net_movement) / NUM_JUMPS);
       printf("Average movement in 10 jumps = %lf " , avg_movement);
       total_avg_movement += avg_movement;
   }
   printf("Average movement over all trials = %lf " , total_avg_movement / trials);
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote