issue with a while loop
Mostra commenti meno recenti
Hey everybody, got a simple question for ya. Im making a function file to determine when it is safe to drive for a person who has been drinking. The value for hours in the output is wrong, but the formula works well outside of the loop. The answer should be around 2-3 hours, but the while loop consistently returns .28 hours. Heres my code
BAC=.13;
Hrs=0;
Rt=.0140;
while BAC>.08
BAC=BAC-(Hrs*.0140);
Hrs=Hrs+.01
end
1 Commento
Azzi Abdelmalek
il 3 Ago 2014
If the formula works well outside the loop, then don't use the loop
Risposta accettata
Più risposte (1)
Star Strider
il 3 Ago 2014
For zero-th order elimination kinetics, the loop should actually be:
BAC=.13;
Hrs=0;
Rt=.0140;
while BAC>.08
BAC=BAC-(0.01*.0140);
Hrs=Hrs+.01
end
This gives Hrs = 3.58.
Categorie
Scopri di più su MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!