A time-step model updates state by applying a rate over a fixed interval.

Program

Play the program to change the interval and watch the position update.

dt
single_time_step.f90
Replay: real traced execution (multi-file project)
program single_time_step_demo
    implicit none
    real :: position
    real :: velocity
    real :: dt

    position = 0.0
    velocity = 4.0
    dt = 1.0
    position = position + velocity * dt
    print '(F0.1)', position
end program single_time_step_demo
program single_time_step_demo
    implicit none
    real :: position
    real :: velocity
    real :: dt

    position = 0.0
    velocity = 4.0
    dt = 0.5
    position = position + velocity * dt
    print '(F0.1)', position
end program single_time_step_demo
program single_time_step_demo
    implicit none
    real :: position
    real :: velocity
    real :: dt

    position = 0.0
    velocity = 4.0
    dt = 2.0
    position = position + velocity * dt
    print '(F0.1)', position
end program single_time_step_demo
  1. position ← 0.0

    7position = 0.08velocity = 4.0
    values this step0.0position
  2. velocity ← 4.0

    7position = 0.08velocity = 4.09dt = 1.0
    values this step4.0velocity
  3. dt ← 1.0

    8velocity = 4.09dt = 1.010position = position + velocity * dt
    values this step1.0dt
  4. position ← 4.0

    9dt = 1.010position = position + velocity * dt11print '(F0.1)', position
    values this step0.0 4.0position4.0velocity * dt
  5. print '(F0.1)', position

    10    position = position + velocity * dt11    print '(F0.1)', position12end program single_time_step_demo
    output4.0
    values this step4.0position
  1. position ← 0.0

    7position = 0.08velocity = 4.0
    values this step0.0position
  2. velocity ← 4.0

    7position = 0.08velocity = 4.09dt = 0.5
    values this step4.0velocity
  3. dt ← 0.5

    8velocity = 4.09dt = 0.510position = position + velocity * dt
    values this step0.5dt
  4. position ← 2.0

    9dt = 0.510position = position + velocity * dt11print '(F0.1)', position
    values this step0.0 2.0position2.0velocity * dt
  5. print '(F0.1)', position

    10    position = position + velocity * dt11    print '(F0.1)', position12end program single_time_step_demo
    output2.0
    values this step2.0position
  1. position ← 0.0

    7position = 0.08velocity = 4.0
    values this step0.0position
  2. velocity ← 4.0

    7position = 0.08velocity = 4.09dt = 2.0
    values this step4.0velocity
  3. dt ← 2.0

    8velocity = 4.09dt = 2.010position = position + velocity * dt
    values this step2.0dt
  4. position ← 8.0

    9dt = 2.010position = position + velocity * dt11print '(F0.1)', position
    values this step0.0 8.0position8.0velocity * dt
  5. print '(F0.1)', position

    10    position = position + velocity * dt11    print '(F0.1)', position12end program single_time_step_demo
    output8.0
    values this step8.0position
time step `dt` is the modeled amount of time advanced by one update.
rate update `velocity * dt` converts a rate into a position change.
state variable `position` is updated in place to hold the new state.