# Fitting curve for Newton's cooling law data programatically?

The data are for the model $T(t) = T_{s} - (T_{s}-T_{0})e^{-\alpha t}$, where $T_0$ is the temperature measured at time 0, and $T_{s}$ is the temperature at time $t=\infty$, or the environment temperature. $T_{s}$ and $\alpha$ are parameters to be determined.

How can I fit my data against this model? I'm trying to solve $T_{s}$ by $T_{s}=(T_{0}T_{2}-T_{1}^{2})/(T_{0}+T_{2}-2T_{1})$, where $T_{1}$ and $T_{2}$ are measurements in time $\Delta t$ and $2\Delta t$, respectively.

However, the results are varying a lot through the whole data set.

Shall I try gradient descent for the parameters?

-
If you use gradient descent, what cost function are you going to minimize? –  littleO Nov 15 '12 at 9:32
I think $T_s$ was actually supposed to be the temperature at time $t = \infty$ (at steady state). Perhaps there was an incorrect edit. –  littleO Nov 15 '12 at 9:39
Yes, t=∞, indeed. The environment is thought to be a source whose capacity is big enough to keep its temperature stable. –  ZhangChn Nov 15 '12 at 11:20