A random walk is where you are standing on a sidewalk and fl

A random walk is where you are standing on a sidewalk and flipping a coin. If you get heads, you take one step in the positive direction. If you get tails, you take one step in the negative direction. You flip the coin a certain number of times, stepping for each flip, and see where you end up on the sidewalk. Write a Matlab program that simulates a series of random walks.

Create an empty array P that is 250 elements long

Set M to the maximum number of trials Set N to the maximum number of coin flips

Repeat the following M times:

Set position to 125 Repeat the following N times:

if a random number from ‘rand’ is less than 0.5, subtract one from position

else add one to position

end N

Add one to P(position)

end M

Plot out P

Use the ‘mean’ and ‘std’ functions to find the mean and standard deviation of P

Solution

m = mean(P);

s = std(P);

A random walk is where you are standing on a sidewalk and flipping a coin. If you get heads, you take one step in the positive direction. If you get tails, you

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site