Created
May 8, 2011 18:33
-
-
Save sengupta/961578 to your computer and use it in GitHub Desktop.
One Dimensional Random Walk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// One Dimensional Random Walk | |
// http://en.wikipedia.org/wiki/Random_walk | |
PossibleSteps = [1, -1] // Assuming you can only go ahead by one step or backwards by one step | |
Start = 0 // Start at 0 on the number line | |
NumberOfSteps = 1000 | |
StepsTaken = sample(NumberOfSteps, PossibleSteps); // Take a random step ahead or back | |
n = length(StepsTaken) | |
Path = StepsTaken*triu(ones(n, n)); // Find the cumulative position | |
plot2d(Path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment