Numerical Simulation and Data Processing
Building Discrete-Time Simulation Models
A discrete-time simulation model predicts a changing system by calculating its condition at separate, specified times. You might track water in a reservoir each day, material moving between tanks each cycle, or stored energy after each operating period. Instead of describing every instant between observations, you apply a rule repeatedly. The useful question is what the system contains now and how one interval changes it.
Choose the state and the clock
The state is the collection of quantities your model records to describe the system at a particular step. For a single water tank, one state variable might be its volume in litres. For two connected tanks, you may need both volumes because knowing only their combined volume does not describe how the water is distributed.
Write xn for a recorded quantity at step n. The initial value x0 supplies the starting condition; x1 is the value after one update. If each step represents one day, step n occurs n days after the start.
Specify whether you record the state before or after scheduled events. A daily delivery can belong to the current update or the next one depending on this choice. Neither convention is automatically preferable, but your description and calculations must agree.
Translate events into an update rule
For a stored quantity, the governing balance is
Each term must have the same units. A flow given in litres per hour must be multiplied by the relevant number of hours before it can be added to a volume in litres.
A common model retains a fraction r of the old amount and then receives an input u:
Here, r is dimensionless and u has the same units as xn. This difference equation becomes a simulation when you start with x0 and repeatedly calculate the next value.
The order of events is part of the model. Compare two possible descriptions of one interval:
Timing of input | Update rule | Meaning |
|---|---|---|
Input arrives after the loss | xn+1=rxn+u | Only the old amount experiences this interval's loss. |
Input arrives before the loss | xn+1=r(xn+u) | Both the old amount and the new input experience the loss. |
Example: A container starts with 30 L, retains 80% during an interval, and receives 5 L. Adding the input after the loss gives 0.80(30)+5=29 L. Adding it before the loss gives 0.80(30+5)=28 L. The different results reflect different timing assumptions.
For several connected stores, calculate every transfer from the states specified by the model. If a fraction p of store A moves to store B each step, with no other changes, simultaneous rules are
Calculate both new values before replacing either old value. Otherwise, the second calculation may accidentally use information from a different step.
Record and check the results
Store outputs in a table with one row per step. Include the initial state in row zero, label units, and distinguish a stored amount from a total accumulated over several steps. Water remaining today and water spilled across all days are different outputs.
Check whether your results obey the model's limits. A physical stored amount should not become negative. Transfers between stores should cancel when you total the whole system; external inputs and outputs change that total. A capacity limit also needs an explicit rule for what happens to excess material.
Finally, a simulation output is conditional on its assumptions. A daily percentage does not automatically become an hourly percentage when you change the step duration. Reconsider the interval rules whenever you change the clock or the system being represented.
What to remember
- Specify the state, its units, the initial values, and the step duration.
- Translate event timing into the update rule.
- Use the correct old states for simultaneous updates.
- Check totals, physical limits, and the meaning of each recorded output.
Example: Tracking Dye Through Two Tanks
A laboratory uses a cycle-based model to track dissolved dye in two connected tanks. Initially, upper tank A contains 50 g of dye and lower tank B contains 20 g. During each cycle, 20% of A's starting dye mass transfers to B, while treatment removes 25% of B's starting dye mass. At the end of the cycle, 6 g of fresh dye enters A. There are no other dye inputs or losses.
The model uses a simultaneous update: all proportional transfers and removals are calculated from the masses recorded at the start of the same cycle. In particular, dye arriving in B is not treated until a later cycle.
a) Let An and Bn be the dye masses in grams after n complete cycles. Write the initial conditions and both update rules.
Tank A loses 20% of its old mass, leaving 80%, and then receives 6 g. Tank B retains 75% of its old mass and receives the material transferred from A. Therefore,
The fractions are dimensionless, so every term in either update has units of grams. Use the old value of A in both equations; calculating B from the newly updated A would change the specified transfer.
b) Calculate the dye mass in each tank after two complete cycles. Give the final masses to two decimal places.
First calculate both states after cycle 1. Tank A retains 0.80(50)=40 g and receives 6 g, giving ________. Tank B retains 0.75(20)=15 g and receives 0.20(50)=10 g, giving ________.
For cycle 2, the transfer from A is ________, calculated as 0.20(46). Treatment removes ________ from B, calculated as 0.25(25). Both calculations use the cycle 1 states.
Now complete the second update:
After two cycles, tank A contains 42.80 g and tank B contains 27.95 g. The newly transferred 9.2 g enters B without experiencing treatment during that same cycle.
c) Find the combined dye mass after two cycles and verify it using the external inputs and removals.
Adding the final tank masses gives
To check this independently, start from the initial combined mass of 50+20=70 g. Two fresh inputs add 2(6)=12 g. Treatment removes 0.25(20)=5 g in cycle 1 and 0.25(25)=6.25 g in cycle 2.
The transfers between tanks remain inside the combined system, so they do not enter its external balance:
The balance agrees with the individual updates. The combined final mass is 70.75 g, an increase of 0.75 g from the starting total.
A delivery simulation exports five predicted journey times: 12, -999, 15, 9 and -999 minutes. Its documentation states that -999 marks a failed run and does not represent a journey time. A valid run is a run that produces a usable journey time.
Complete the missing processing steps for calculating the average over valid runs. Exclude failed-run markers from both the sum and the count.
Add the valid journey times to obtain minutes. Divide this sum by , the number of valid runs, to calculate the average journey time.
A laboratory reservoir starts with 25 L. During each operating cycle, 80% of the starting water remains, and 10 L is then added. Its model is Vn+1=0.80Vn+10, with V0=25 L. Complete the end-of-cycle volumes below in litres. Enter exact decimal values without rounding.
| Completed cycles | Volume (L) |
| 0 | 25 |
| 1 | |
| 2 | |
| 3 | |
| 4 |