Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Pa starts from barn and every second takes one step. One day Pa starts to wander off, and notices that the grass has been mysteriously
Pa starts from barn and every second takes one step. One day Pa starts to wander off, and notices that the grass has been mysteriously cut to resemble graph paper. Notice that after one step Pa is always exactly one unit away from the start. Lets assume that Pa wanders eastward from the initial location on the first step. How far away might Pa be from the initial location after the second step? John sees that with a probability of Pa will be units away, with a probability of Pa will be units away, and with probability of Pa will be units away. On average Pa will be further away after two steps than after one step. If the second step is to the north or south, the third step will bring the farmer closer to origin half the time, further half the time. The third step will be away from the origin. If the second step is to the east the third step will be closer to origin a quarter of time, and further away three quarters of time.
It seems like the more steps Pa takes, the greater the expected distance from the origin. We could continue this exhaustive enumeration of possibilities and perhaps develop a pretty good intuition about how this distance grows with respect to the number of steps. Pas wife MiMa another grandparent of Johns also likes to wander away randomly, but riding a mule. The mule goes South twice as often as any other direction. Lastly, Johns hog Reg has an odd habit of wandering off too, but only randomly going east or west at each step, never north or south. Your Python program ought to model these two as well. Info on intructions:
simulate
Define a function called simulate that takes three parameters:
A list of walk lengths to simulate,
The number of trials how many times to do walks of the specified lengths and
Which walker we are modeling: PaMiMa 'Reg or 'all
For your convenience, define a main function that runs with conditional execution, per usual main should read the following three arguments from the command line:
A list of commaseparated walk lengths to simulate there should be no spaces in this list
the number of trials, or times to try each walk length, and
which type of walk we are modeling: PaMiMa or Reg or 'all
If invoked with python randomwalk.py all, your main function should call simulate 'all'
Assume the wanderer always starts each walk at in an infinite grid. On individual tests, your output values should be close to the examples given below, though they wont be exactly the same. The format of the output should be the same.
Pa random walk of steps
Mean CV
Max Min
Pa random walk of steps
Mean CV
Max Min
MiMa random walk of steps
Mean CV
Max Min
MiMa random walk of steps
Mean CV
Max Min
Reg random walk of steps
Mean CV
Max Min
Reg random walk of steps
Mean CV
Max Min
In the output above:
Mean is the average distance over all walks of that length as the crow flies,
Max is the longest distance as the crow flies,
Min is the shortest distance as the crow flies, and
CV is the Coefficient of Variance, defined as the standard deviation divided by the mean.
Round all values to one decimal point, as shown.
All distances should be in steps.
plot
Define a function called plot that plots a sample of final locations in a turtle window in order to visualize their behaviors. plot should expect no arguments. Your output should be similar to the picture below. Do only one plot: plot all three characters for trials on walk length Dont plot the walk length; it takes too long.
guidesimgrandomwalk
Details of plot
In order to ensure that your output matches expected output, do the following:
Use turtle.shapedocs to change the turtles shape the three shapes are 'circle 'square and triangle
Use turtle.colordocs to change the turtles color black 'green and red
Use turtle.stampdocs to plot individual points.
Use turtle.shapesizedocs to scale the shapes to half of their original size in both dimensions.
Use turtle.speeddocs and set it to the fastest speed if you have trouble with timing out.
Use a scale of five pixels for the turtle per step for Pa MiMa or Reg
Set the size of the screen to x
When you are finished, call the provided savetoimage function
I have some code done. But Im not sure what I need to change about it The rubric, expectedneeded output, and my code so far is in the picture.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started