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

Using Matlab, perform 100 trials of this race while recording position (both tor

ID: 3840193 • Letter: U

Question

Using Matlab, perform 100 trials of this race while recording position (both tortoise and hare) and time into an array for each.

You are to write a program that recreates one of the truly great moments in history: the classic race of the tortoise and the hare. You will use random number generation to develop multiple simulations of this event, and estimate how likely each isto win a given race. The racetrack is 4.2 miles long. The first contender to travel that distance wins. The course weaves its way up the side of a slippery mountain, so occasionally the contenders lose ground. The competitors can move in a variety of actions, which move them forward or backward at a certain velocity. After doing one action for a specific time, they immediately do another one. Each action has a certain frequency of occurrence (assumed to be independent of previous actions. The action type, velocity, time to complete, and frequency for each competitor is shown in the following table. Animal Action Type Frequency Time to complete Velocity 20Ro Tortoise Fast Plod 2 minutes Forward at 2 mph Forward at 2 mph Slow plod. 60% 4 minutes Slip minute Backward at 1 mph Hare Sleep 20Ro 45 minutes No movement 10% 1 mimute Forward at 10 mph Small hops 40% 5 minutes Forward at 3 mph Big Slip Backward at 8 mph 10% 1 mimute Backward at 3 mph Small slip 1 mimute

Explanation / Answer

tortoiseMove = [2, 0.5, -1];
tortoiseTime = [2, 4, 1];
tortoiseCFreq= [0.2, 0.8, 1];
rabbitMove = [0, 10, 3, -8, -3];
rabbitTime = [45, 1, 5, 1, 1];
rabbitCFreq= [0.2, 0.3, 0.7, 0.8, 1];

tortoiseTotalTimeArray = rand (1, 100);
rabbitTotalTimeArray = rand (1, 100);


for i= 1:100
tortoiseDist = 0;
rabbitDist = 0;
tortoiseTotalTime = 0;
rabbitTotalTime = 0;
while tortoiseDist < 4.2
    tortoiseChoise = V1 = find(tortoiseCFreq > rand(1), 1, 'first');
    maxDist = tortoiseMove(tortoiseChoise)*tortoiseTime(tortoiseChoise)/60;
    if maxDist + tortoiseDist < 4.2
        tortoiseDist = maxDist + tortoiseDist;
        tortoiseTotalTime = tortoiseTotalTime + tortoiseTime(tortoiseChoise);
    else
        tortoiseTotalTime = tortoiseTotalTime + tortoiseTime(tortoiseChoise)* (4.2 - tortoiseDist)/maxDist;
        tortoiseDist = 4.2;
    end
end

while rabbitDist < 4.2
    rabbitChoise = V1 = find(rabbitCFreq > rand(1), 1, 'first');
    maxDist = rabbitMove(rabbitChoise)*rabbitTime(rabbitChoise)/60;
    if maxDist + rabbitDist < 4.2
        rabbitDist = maxDist + rabbitDist;
        rabbitTotalTime = rabbitTotalTime + rabbitTime(rabbitChoise);
    else
        rabbitTotalTime = rabbitTotalTime + rabbitTime(rabbitChoise)* (4.2 - rabbitDist)/maxDist;
        rabbitDist = 4.2;
    end
end
rabbitTotalTime

tortoiseTotalTime

if (rabbitTotalTime > tortoiseTotalTime)
    printf("Tortoise wins ");
else
    printf("Rabbit wins ");
end

tortoiseTotalTimeArray(i) = tortoiseTotalTime;

rabbitTotalTimeArray(i) = rabbitTotalTime;

end