Consider a frog that can jump left or right any number of units. For example, he may jump left 4 units (i.e. -4), then right 2 units (i.e. +2), then right 1 unit (i.e. +1), et cetera. If I record the lengths of all of his jumps, after a time I will have a probability mass function (as space is discrete in this problem, not continuous) that describes the distribution of his movements. With me so far? I believe I can determine the mean by a running total (called total) adding on each jump length (called d), as below:
- Code: Select all
total+=d;//For each jump
...
total/=n;//At end of simulation
If the distribution is symmetric, the variance could be calculated as
- Code: Select all
variance+=pow(d,2);//For each jump
...
variance/=n;//At end of simulation
Hah. Actually not such a long post!
