Logo C++ Online Judge

C++

TA:
统计

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.

提交

Written answers receive AI rubric assessment.

Up to 3 submission attempts per student. Sign in to see your remaining attempts.

Each submission includes all questions. Review your answers before submitting.

Short explanations are welcome. You may leave answers blank; unanswered questions receive zero credit.

1. Which program is better supported by these observations as a correct implementation of the rule? (10 points)
2. Explain the observation or property supporting your choice. You do not need to determine the coefficients or guess either program’s code. (20 points)
3. How could the program apply the stated rule using one n-element array and only a fixed small number of extra variables? Explain what information must be kept while the program moves through the array. (35 points)
4. Would a program that faithfully applies this mathematical rule describe the insulated experiment? Explain how you would assess that claim using the supplied physical facts, and identify any part of the model that would need reconsideration. (35 points)
Drafts are saved in this browser every 30 seconds.