MATLAB Tutorial

 

The problem - to cross the seven bridges in a continuous walk without recrossing any of them - was regarded as a small amusement of the Konigsberg townfolk. Euler, however, discovered an important scientific principle concealed in the puzzle... Thus began a vast and intricate theory, still young and growing, yet already one of the great forces in modern mathematics.
-James Newman
 

The following is example a function written using MATLAB that simulates a 1-dimensional random walk.  After the short description in the lab

use the code below to answer the questions that follow.

 

function tt=calc(n,m)

dist=0;

plot(0,0)

axis([0 n -m m])

hold

for i=1:n

    x=floor(6*rand)+1;

    chk=rem(x,2);

    if chk == 0

       dist=dist+1;

    else

        dist=dist-1;

    end

    p(i)=dist;

end

plot(p)

hold

 

  1. Once the walker leaves the starting point is he likely to return?

  2. If you answered yes, to the above what is the average number of steps before the walker returns to the starting point?

  3. What is the average distance the walker travels before returning to the starting point?

  4. What is the probability that the walker will make it 45 steps away from the starting position?

  5. What is the probability that the walker will make it 90 steps away from the starting position?

Now alter the code above to "flip" a coin to simulate a 1-diminesional random walk.  That is, if  "heads", take a step forward if "tails", take one step back.

Finally, make it so that the coin is not fair for example make sure heads occurs 51% of the time.  Answer the above questions about this new random walk.