issue with a while loop
Mostrar comentarios más antiguos
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 comentario
Azzi Abdelmalek
el 3 de Ag. de 2014
If the formula works well outside the loop, then don't use the loop
Respuesta aceptada
Más respuestas (1)
Star Strider
el 3 de Ag. de 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.
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!