FreeCampus Python

Milestone Challenge: Test a Cooling Model against Measurements

Evaluate a model with arrays, symbolic reasoning, plotting, and a SciPy root finder.
Open in Colab
  • Goal: Evaluate a model with arrays, symbolic reasoning, plotting, and a SciPy root finder.
  • Estimated time: 2–4 hours of active work.
  • Before starting: Complete the milestone units and their unit challenges.
  • Keep: Your source, observed outputs, checks, and a debugging note.

This community challenge is ungraded. Use the checks to review your own work; there is no submission service or automatic grade. Completion is self-reported in this browser on this device.

1. Test a cooling model against measurements

Use the fictional model T(t) = 20 + 60exp(-0.1t), with minutes and degrees Celsius. Evaluate at 0, 5, 10, 15, 20 minutes; observations are 80, 57, 43, 34, 28. Calculate observed-minus-predicted residuals, plot both series, and find when T reaches 30 using scipy.optimize.brentq on [0, 40]. Compare with 10*log(6).

Predict an ordinary result before coding. Start with the smallest part you can run and inspect. Use Colab for notebooks and the local workspace introduced in the units for packaging or command-line tasks.

2. Set up the experiment

import numpy as np
from scipy.optimize import brentq

times = np.array([0, 5, 10, 15, 20], dtype=float)
observed = np.array([80, 57, 43, 34, 28], dtype=float)

def temperature(t):
    return 20 + 60 * np.exp(-0.1 * t)

# Compute predictions, residuals, and crossing time.

The starter is deliberately incomplete. Implement the contract; do not change the expected results to match an incorrect implementation.

3. Check the observable results

  1. T(0) is 80 and predictions approach 20 from above.
  2. Residuals match the observation shape and documented subtraction direction.
  3. The crossing is approximately 17.9176 minutes; compare symbolic and numerical values with tolerance 1e-4.
  4. Endpoint values bracket the target: T(0)-30 > 0 and T(40)-30 < 0.
  5. Plots distinguish measured and predicted values, with units and a legend.

Record actual outputs beside predictions. Reduce a failure to a small example, change one cause at a time, and repeat the failed check after repairing it.

4. Change one condition

Change the target to 15 and explain why no nonnegative crossing exists before invoking a solver. Repeat with 40. Do not claim this fictional model proves how a real object cools.

5. Review a hint after attempting the task

Hint: connect the relevant tools

Vectorize predictions with temperature(times); use temperature(t) - target for the root finder. Check endpoint signs and compare with hand algebra or SymPy.

6. Explain and self-review

Deliver a reproducible notebook, labeled plots, tolerance checks, and a short note on residuals and model limits. Explain why matching one target time does not validate an entire physical model.

Review path: compare your result with the contract

Check the ordinary result first, then the boundary cases and changed condition. Explain which rule justifies each result. An implementation that differs from the hint can still satisfy the contract; explain why yours does.

7. Save your work and record completion

Save the notebook or project somewhere you control. Include one decision, one failed check, its repair, and a result you can reproduce. Record completion after reviewing the checks; you can undo it later.

Not yet recorded.

Return to the milestone overview.

Back to top