I don\'t need a complete solve. I need help on how to incorperate the \"Time to
ID: 3843214 • Letter: I
Question
I don't need a complete solve. I need help on how to incorperate the "Time to complete" portion of the table into my script. As you can see, my script works as though ever action is on a 1 minute interval, which isn't the case. Fast plod takes 2 minutes @ 0.0333mpm and slow plod takes 4 minutes @ 0.0083mpm. I want to do something along the lines of, in the case of fast plod, a vector <previous_distance+0.0333,previous_distance+0.0333> to reflect the distance and time, and adding that to my current distance in my while loop...or something like that
Here's what I have for the tortoise part:
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
first of all you are not incrementing distance .
make it like this distance=distance + Fp*t
secondly make a vector t=[2,4,1];
and a scalar variable timetocomplete=0;
the make following changes
---------------------------------------------------------------------
clc
clear
%% Conversion mph to mpm
% Tortoise stuff (mpm)
FP=2/60;
SP=0.5/60;
S=-1/60;
%% Tortoise
distance=0;
t=[2,4,1];
timetocomplete=0;
while distance<4.2
for action_type=randi([0 100])
if action_type<=20 % if 20% fast plod
fprintf('fast plod')
timetocomplete=timetocomplete+t(1);
distance=distance+FP*t(1)
elseif action_type>=20 && action_type<=80 % if 60% slow plod
fprintf('slow plod')
timetocomplete=timetocomplete+t(2);
distance=distance+SP*t(2);
elseif action_type<=100 && action_type>=80 % if 20% slip
fprintf('slip')
timetocomplete=timetocomplete+t(3);
distance=S*t(3);
end
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.