How Fast Does Your Coffee Cool? Modeling Everyday Heat Loss in MATLAB
Summary
This MATLAB-based activity guides students through simulating the temperature decay of a hot beverage in a coffee mug using Newton's Law of Cooling. Students are provided with the governing differential equation and system parameters and focus primarily on coding the model using MATLAB's ode45 solver. Through this hands-on coding exercise, students explore the thermal performance of different mug types (ceramic, insulated, metal), visualize heat loss over time, and compare results using plotting tools. The activity is suitable for freshman and sophomore mechanical engineering students and is adaptable to both in-person labs and online instruction.
Learning Goals
Conceptual Goals: Students will be able to
- Understand and apply Newton's Law of Cooling in a real-world context.
- Observe and interpret how heat transfer parameters influence cooling rates.
Computational Goals: Students will be able to
- Practice implementing first-order differential equations using MATLAB.
- Use ode45 to solve time-dependent models and generate time series data.
- Create meaningful, labeled plots using plot, xlabel, ylabel, and legend.
Higher-Order Thinking Skills:
Compare simulation results to evaluate thermal performance across design variations.
Analyze model sensitivity to parameters (e.g., heat transfer coefficient and surface area).
Reflect on model assumptions and suggest real-world modifications (e.g., adding a lid).
Other Skills Developed:
Clear documentation of MATLAB code with comments.
Data presentation through graphing and visual analysis.
(Optional extension) Technical writing via a brief report or response to analysis questions.
Context for Use
This activity is designed for introductory computation course for Mechanical Engineering students. It is appropriate for first- or second-year college students (college lower division) at a wide range of institution types, including universities and community colleges. The activity is intended as a class activity or take-home assignment, requiring approximately 20–40 minutes to complete.
Students should have basic familiarity with MATLAB syntax, including defining variables, using built-in functions like ode45, and generating simple plots. No prior experience with differential equations is necessary, as the governing formula is provided.
This is a beginner-friendly exercise that bridges basic physics (heat transfer concepts) with practical computation. It can be used as a standalone activity to reinforce MATLAB programming skills or integrated into a broader unit on modeling physical systems. The activity is also easily adaptable for use in online learning environments where students have access to MATLAB or MATLAB Online.
Description and Teaching Materials
This activity uses MATLAB to simulate the cooling of a hot beverage in a coffee mug using Newton's Law of Cooling. Students are provided with the governing equation and all necessary physical parameters and focus on implementing the mathematical model using MATLAB's ode45 solver. The simulation helps students explore how thermal properties—such as surface area and heat transfer coefficient—affect the rate of cooling.
How MATLAB is Used:
Students use MATLAB to:
Define physical parameters of the system (mass, heat capacity, heat transfer coefficient, etc.).
Construct an anonymous function representing the ODE dT/dt=1/tau(T-Troom)
Solve the ODE using ode45.
Plot and compare temperature-time curves for various mug types (ceramic, metal, insulated).
Included Teaching Materials:
coffee_coding_focus.m (Starter MATLAB script)
A structured script where students input physical parameters, implement the ODE, and generate plots. Includes placeholders for experimentation with different mug types.
Activity Prompt Handout (PDF)
Provides:
Full problem description
Equation already derived for students
Table of parameters for different mug types
Step-by-step instructions
Space for plot interpretation and answers
Supplemental Image (PNG)
An illustration showing ceramic, metal, and insulated mugs to aid visualization. Helps connect computation to physical intuition and supports inclusive visual learning.
MatlabCode.m (Matlab File 3kB Oct31 25)
Student Handout (Acrobat (PDF) 4MB Sep4 25)
Teaching Notes and Tips
This activity works well when students already have some experience with MATLAB basics (variables, functions, plotting). Instructors may wish to briefly review the ode45 syntax and the concept of anonymous functions in MATLAB before students begin.
Common student errors include:
Forgetting to use element-wise operations (e.g., .*, .^) when modifying formulas.
Confusion between units (especially for time, temperature, or converting seconds to minutes).
Misinterpreting ode45 output: students may not realize the time vector returned is not evenly spaced.
We recommend:
Live-coding the first 3–5 lines of the starter script in class.
Providing a reference plot (with proper labels) to guide students in verifying their output.
Encouraging clean documentation and incremental testing (e.g., first test the ODE, then add plotting, then try multiple mug types).
This activity can be adapted for:
Homework (if MATLAB access is available remotely).
Competency-building modules in thermal fluids, system modeling, or even introductory physics.
Optional extensions like adding a lid, variable room temperature, or using Euler's method offer flexibility for higher-performing students or honors sections.
Assessment
Student understanding can be assessed through:
MATLAB Script Submission – The script should run without errors, simulate at least two mug types, and include commented code. Partial credit can be awarded for well-structured but partially incorrect code.
Plot Quality – Students should produce a labeled plot showing cooling curves for multiple mugs, including a legend and clear axis labels.
Short Answer Reflections – Prompts like "Which mug kept coffee hotter longer and why?" and "How does surface area affect the time constant?" allow instructors to gauge conceptual understanding.
Optional Extensions – Bonus points can be awarded for exploring the lid scenario, variable room temperature, or Euler's method and discussing differences with the baseline case.
Rubrics may assign weight across the script (40%), plot and results (30%), and explanations (30%).
References and Resources
Web Resources:
MathWorks – ode45 Documentation
https://www.mathworks.com/help/matlab/ref/ode45.html
Provides detailed explanation and examples of using MATLAB's built-in ODE solver.
Wikipedia – Newton's Law of Cooling
https://en.wikipedia.org/wiki/Newton%27s_law_of_cooling
Offers background on the physical model used in the activity, including assumptions and limitations.
![[creative commons]](/images/creativecommons_16.png)