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
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.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.