Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are a sheep herder and like any good sheep herder your job is to herd some sheep. Lacking a good sheep dog, you decide
You are a sheep herder and like any good sheep herder your job is to herd some sheep. Lacking a good sheep dog, you decide that the best plan of action is to build a wall that parallels both sides of a path in an attempt to prevent your flock from straying away from the correct direction. Assuming that the correct path is denoted by position 0, the bordering wall you decide to build will be at W (Note: we will keep W 1 otherwise strange stuff happens!). Of course, the integrity of your wall will be key to successfully herding these sheep. You can either spend the money and build a good wall, try and limit your budget and build a mediocore wall or really cut the budget and build a terrible wall. What does a young enterprising sheep herder do? Fortunately for you, though you may herd sheep during the day you moonlight as an up and coming MATLAB programmer at night. What better way to simulate these possible scenarios? Some basic assumptions are needed of course. For starters, all sheep start on the path (i.e. xk(1) = 0). Additionally you assume a random walk for each sheep. Meaning at step i + 1 the position, xk, of sheep k is determined by xk(i + 1) = xk(i) + k(i) where k(i) is a Gaussian random variable (Note: each sheep has its own random walk meaning that you shouldnt use the same k(i) for all sheep otherwise your program is trivial). Of course, these sheep are not the brightest and before you know it they will run into the walls. How well you construct these walls determines what happens when a sheep collides with the wall 1. If you built a good wall, then the sheep will bounce off the wall. Meaning if xk(i + 1) W, then xk(i + 1) = W |W xk(i + 1)|. Additionally if xk(i + 1) W, then xk(i + 1) = W + | W xk(i + 1)|. If done correctly, a sheeps position should be W < xk < W 2. If you cut the budget all the way down and build a terrible wall, any sheep that hits or exceeds the wall position will get stuck in the wall! A sheep thats stuck stays stuck and its position will not change from that point forward. 3. If you built a mediocore wall, theres a 50% chance that either of the above happens. Meaning if a sheep hits or exceeds a wall, a flip of a coin determines if a sheep bounces off the wall or gets stuck. Again, a sheep that is stuck stays stuck. 1 The goal of this project is to build a function sheepWalk.m which simulates these possibilities. Here are the requirements for the function Function output- position of sheep at each step Function input- number of sheep, number of steps to simulate, location of wall (i.e. W) Must present a menu to select which type of wall to build Function plots position of all sheep. Graph should have informative labels. Title should indicate which wall is being built. Indicate on graph where the boundaries (i.e. W) are (HINT: line command in MATLAB). Outside of these requirements, how you build the function is up to you. There are several different ways to get to the same solution. Note: the code you write should work for an arbitrary number of sheep (i.e. if you input 100 sheep everything should work just as well as if you input 1 sheep)
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