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

A random walk is where you are standing on a sidewalk and flipping a coin. If yo

ID: 3378272 • Letter: A

Question

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

Explanation / Answer

m = mean(P);

s = std(P);

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