A program divides a rod into n equally sized cells and stores their temperatures in an array. At each time step it holds the two end cells at zero and updates each interior cell using
new[i] = (a * old[i - 1] + b * old[i] + a * old[i + 1]) / c
The constants satisfy a > 0, b >= 0, and c = 2 * a + b. Their numerical values are not disclosed. Both programs described below are supposed to use the same fixed constants in every run.
Every old value belongs to the start of the step, and every new value to its end. Assume n >= 3, initialized arrays, and values small enough to avoid overflow. The rule is supplied; you do not need to derive it from physics.
Two experimental reports. Programs X and Y each claim to implement this rule. Their code is not shown. One step produces:
| Starting temperatures | Program X | Program Y |
|---|---|---|
| 0, 16, 32, 48, 0 | 0, 16, 32, 32, 0 | 0, 16, 32, 32, 0 |
| 0, 48, 32, 16, 0 | 0, 32, 28, 15, 0 | 0, 32, 32, 16, 0 |
The two runs use the same constants. Treat the reported results as exact; rounding is not an explanation for their differences. You may reason from relationships between the runs without finding the constants or calculating each output.
Implementing the rule with limited storage. Separately, a program must apply the stated rule to a very long rod. There is room for only one array of n temperatures and a fixed small number of extra variables. The program may visit elements one at a time and overwrite array entries. It must produce every next temperature from the values that existed at the start of that time step. Describe a method in words; no implementation is required.
Connecting the calculation to an experiment. The real rod to be predicted is insulated at both ends and along its sides: no heat enters or leaves it. There are no heat sources inside. Take as given that its total heat stays constant and that the equal-sized cells have equal heat capacity. Their temperature sum is therefore proportional to total heat.
Initially, some interior cells are warm and the end cells are at zero. The program will repeatedly apply the given rule, including holding the end cells at zero. A developer offers to verify every step against the mathematical rule before the program is used for this experiment.
