**Need help with data science or mathematical modeling?**I do consulting work in Norway. Read about my previous work experience and reach out to me for more information.

# How hot can my barbecue grill get?

- 9. May 2020
- #statistics, #mathematics

My gas-fueled barbecue grill has a thermometer that goes up to \(370\) degrees Celsius. However, when I leave it on for a long time the temperature rarely surpasses \(200\) degrees or so. How hot will the grill get if I leave the gas on indefinitely?

In this article we collect data, use basic thermodynamics to model the system, fit the model to observed data, and obtain probabilistic estimates of the maximum temperature \(T_{\text{max}}\) that the grill will reach. We show that the \(99 \, \%\) credible interval of the maximum temperature \(T_{\text{max}}\) is \([232.1, 250.4]\), and posterior mean is \(240.6\) degrees Celsius.

# Table of contents

# Observed values

The figure below shows observed values of temperature \(T\) as we heat the grill. The observations were obtained by filming the thermometer attached to the grill for \(11\) minutes as the grill heated up. A total of \(n=31\) observations \((T_i, t_i)\) were extracted from the video, where \(T\) denotes temperature and \(t\) denotes time.

The observations are not equidistant with respect to time. There are likely measurement errors present due to both (1) the cheap thermometer and (2) my crude reading of the thermometer.

# Thermodynamic model

We could start fitting curves to the data immediately, but *if we ignore the physics of the system we might fit the wrong kind of function*.
For instance, though a logarithmic curve might fit the observed data nicely, it’s the wrong model for this particular system.
In this section we derive a thermodynamic model for the temperature \(T\) as a function of time \(t\).

## Heat and total energy

Let \(Q_{\text{in}}\) be the infinitesimal rate of which heat enters the system (i.e., the grill) and \(Q_{\text{out}}\) be infinitesimal rate of which heat leaves the system. The total energy within the system at time \(t\) is given by \(U(t)\), defined as the sum of the net flux of heat:

## Heat in and out of the system

The burning gas is responsible for adding energy to the system, and we assume that heat enters the system at a constant rate. In other words, we take \(Q_{\text{in}}\) to be a constant independent of time.

We assume that heat leaves the system through conduction, in which case the transfer of heat obeys *Fourier’s heat conduction law*.
The law states that *heat leaves the system in proportion to the difference between the system temperature \(T\) and the outside temperature \(T_0\)*.

The *outside temperature is equal to the initial temperature of the system*, hence the name \(T_0\) in the equation above.
The variable \(a\) expresses the proportionality.

## A differential equation

Differentiating the equation above and substituting the value for \(Q_{\text{out}}\) we obtain:

The *heat capacity* of a material is defined as the amount of heat needed to produce a unit change in temperature.
Our system has no large variation in either pressure or temperature, so we can safely assume that the heat capacity is constant.
As a result, the change of energy \(U\) is proportional to the change in temperature \(T\).
Mathematically we express this as \(dU = b \, d T\), where \(b\) is an unknown constant that depends on the material type and its mass.

We want to use temperature as the dependent variable to describe the system, so we substitute \(dU\) for \(b \, d T\) and obtain the differential equation

This is a first order, inhomogeneous differential equation in \(T(t)\). The solution is given by:

The solution can be verified by differentiating and plugging \(T(t)\) and \(T'(t)\) into the differential equation.

## Re-parametrization of the equation

At this point there are many variables that we do not care about, so we re-parameterize the equation by introducing new variables \(T_{\text{max}} := T_0 + Q_{\text{in}} / a\), \(\Delta T := -B\) and \(k := a /b\).

Substituting these new variables into the equation above, we obtain **the final model**:

The equation above governs the system, and it has some nice, interpretable properties:

# Curve fitting

In this section we fit the observed data to the model equation

We use the *trust region reflective algorithm* implemented in `scipy.optimize.curve_fit`

, with sensible initial guesses and non-negativity constraints.
The result is shown in the figure below.

The model fits the data well, and the parameter estimates obtained are:

According to the model, **the grill will reach approximately \(240.5\) degrees Celsius if left on indefinitely**.
This is disappointing as the thermometer goes all the way up to \(370\) degrees Celsius.

## Prediction errors

The figure below shows the mean and standard deviation of the absolute percentage error when fitting on \(\ell\) data points and predicting on the remaining \(n-\ell\) data points. In the figure, \(\ell\) ranges from \(5\) to \(25\). After \(10\) observations the model suddenly improves. As more data is seen, the model improves its predictions further.

# Bayesian curve fitting

We have obtained non-probabilistic estimates for the parameters through curve fitting. For instance, we saw that \(\widehat{T_{\text{max}}} = 240.5\). This is useful information, but we would like to know the uncertainty in the parameter estimates as well.

In order to obtain estimates of the uncertainty in the model parameters, we define prior distributions and employ Bayesian statistics. The following priors were chosen:

The observations were modeled as follows, where the index \(i\) denotes an observation:

A more robust approach would be to use the Student’s t-distribution or Laplace distribution instead of the normal distribution, but we chose the normal distribution for simplicity.

The posterior distribution of \(\mu\) is shown in the figure below, and is extrapolated to future times.
The observation noise \(\sigma\) is not accounted for in the figure.
In other words, the figure shows the *distribution over models*, not the *distribution over observations* (which would have more uncertainty).

The posterior distributions over \(T_{\text{max}}\), \(\Delta T\), \(k\) and \(\sigma\) given the data is shown below. The small black lines on the horizontal axis show the estimates obtained by the curve fitting routine used in the previous section.

From the figure, we see that the **credible interval of the maximum temperature \(T_{\text{max}}\) is \([232.1, 250.4]\), and posterior mean is \(240.6\) degrees Celsius**.
The posterior mean of the noise, i.e., \(\mathbb{E}[\sigma \mid \text{data}]\), is \(2.93\).

Finally we animate the posterior predictive distribution of \(T\), this time including the measurement noise \(\sigma\). It’s interesting to see how the uncertainty generally decreases as more data is seen, but when the data point at \(t=360\) is added the measurement noise increases somewhat.

# Summary

While it’s tempting to go straight to curve-fitting once data is obtained, more insight can be extracted once a proper system model is constructed. This is true whether the system is physical or not – assumptions determine model equations, which in turn contribute to our understanding of the system.

Standard curve fitting works well. The advantage of our Bayesian approach is mainly uncertainty estimates of the model parameters. The fact that the thermometer goes to \(370\) degrees is merely a marketing gimmick. We expect with high probability that the maximum temperature of the grill is somewhere in the range \([232.1, 250.4]\), and most likely \(240.6\) degrees Celsius.

# Notes and references

- We solved a differential equation of the form \(b T' + aT = c\). This equation is relatively simple, so I solved it by guessing a solution. A good reference for differential equations and applied mathematics in general is
*“Foundations of Applied Mathematics”*by Greenberg. It contains information about Fourier’s heat conduction law as well. - For more information about thermodynamics, see
*“Thermal Physics”*by Schroeder.