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

I don\'t need a complete solve. I want somebody to check my work so far. I can\'

ID: 3840471 • Letter: I

Question

I don't need a complete solve. I want somebody to check my work so far. I can't seem to incorperate the 'Time To Complete' portion into my script. If anybody can guide me, that'd be cool.

Here's what I have so far:

clc
clear
%% Conversion mph to mpm
% Tortoise stuff (mpm)
FP=2/60;
SP=0.5/60;
S=-1/60;
%% Tortoise

distance=0;
ind=1;
t(ind)=1;

while distance<4.2
for action_type=randi([0 100])
if action_type<=20 % if 20% fast plod
ind=ind+1;
fprintf('fast plod')
t(ind)=t(ind-1)+1;
distance=FP*t
elseif action_type>=20 && action_type<=80 % if 60% slow plod
ind=ind+1;
fprintf('slow plod')
t(ind)=t(ind-1)+1;
distance=SP*t;
elseif action_type<=100 && action_type>=80 % if 20% slip
ind=ind+1;
fprintf('slip')
t(ind)=t(ind-1)+1;
distance=S*t;
end
end
end

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

Answer: To incorporate "Time to Completion", you need to measure time elapsed in completing a given action type. In MATLAB, there are two commands that can be used to keep record and measure a time interval. These are: 'tic' and 'toc'. 'tic' is used to start a stopwatch timer, while 'toc' is used to measure the elapsed time.

'tic' should be called at the start of the task and 'toc' can be called whenever you need to measure the elapsed time i.e. to check whether time alloted for a given action type is completed or not. For ex.:

---------------------------------

timer_val=tic;

x=2;

y=3;

z=x+y;

disp(z);

elapsed_time=toc(timerval);

-----------------------------------------

You will need to call tic only once, while toc at the end of every action. If time limit of that action is reached, stop that action and start next action and if not, repeat the previous action.

Also you need to define simulation for Hare too.

Hope this helps you.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote