How many laps a runner can make for 45 minutes with increasing 10% of running time in each lap
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Takashi Fukushima
am 7 Nov. 2019
Kommentiert: Takashi Fukushima
am 7 Nov. 2019
Hello,
I would like to write a program to calculate how many laps a runner can make for 45 minutes with 10% increase of his or her running time in each lap.
The runner run the first lap in 1 minute.
Here is what I have.
lapcounter=1;
running_time=1;
runningtime_total=0;
runningtime_allowed=45;
number_lap=0;
while lapcounter<=runningtime_allowed
lapcounter=lapcounter+(lapcounter*0.10);
running_time=lapcounter+(lapcounter*0.10);
runningtime_total=running_time+(running_time*0.10);
disp("Time: " + runningtime_total);
number_lap=number_lap+1;
end
disp("Number of lap: " + number_lap);
I think I get the idea of how to calculate running time in each lap like running time = lap time*(lap time*0.10), but I need to add the time the runner has been running so that I can know how many laps he or she can make for 45 minutes.
I appreciate your response in advance.
4 Kommentare
the cyclist
am 7 Nov. 2019
Bearbeitet: the cyclist
am 7 Nov. 2019
Without yet thinking too deeply about your code, I'm pretty sure your while condition is wrong.
You don't want
lapcounter<=runningtime_allowed
which would be a comparison like "6 laps is less than or equal to 45 minutes".
You want to compare your total running time to what is allowed, not your number of laps.
In general, your code seems to badly mix up the lap count and the running time.
A statement like
lapcounter=lapcounter+(lapcounter*0.10)
is going to give you a fractional number of laps, but you just want an integer counter for that. (But you also seem to have two variables for tracking laps for some reason.)
I recommend writing out your algorithm in words or pseudocode first, to make sure that it makes sense conceptually. Then convert it to MATLAB code.
Is this a homework problem?
Akzeptierte Antwort
David Hill
am 7 Nov. 2019
function laps=runTrack(t,dt,rt)
%first lap time: t
%total run time: rt
%percent increase in each lap: dt
M=cumsum(t*((1+dt)*ones(1,100)).^(0:99));%pick a number of laps that will not be exceeded (I chose 100)
laps=find(M<=rt,1,'last');
end
The output (laps) gives the total number of laps the runner can complete in rt minutes when the runner's first lap time is t, and it increases by dt each lap.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matched Filter and Ambiguity Function finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!