Timing an energy-reduction loop

A MATLAB simulation models an energy-reduction test. Each completed cycle takes 4 s and halves the stored energy. Assume these updates describe the model exactly, with no additional elapsed time.


MATLAB
energy = 120;              % J
time = 0;                  % s
while energy > 20
    energy = 0.5*energy;
    time = time + 4;
end


What is the final value of time? Answer in seconds, to one decimal place.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Conditional Statements and Loops Questions: