# What is the formula to find the temperature at a specific location of a material as a function of time that is gaining or losing heat?

Imagine a scenario where there is a homogenous material and at a any location in that object I know the temperature at time 0. Given some properties of that material, how can I find out at any other location in that object, what the temperature will be at a certain time.

This applies to 2d and 3d. The object can be gas, liquid or solid.

I am not looking for one general equation for all the possible scenarios. If there are multiple equations that's actually better.

I am a noob in thermodynamics, so please do not make your answer too complicated. My goal is to basically create a simulator for heat transfer.

You'll need to read up on a little bit of mathematics to numerically solve problems like this.

You need to solve the heat diffusion equation for the temperature $T(\vec{r},\,t)$ as a function of time $t$ and position $\vec{r}$:

$$\frac{\partial\,T}{\partial\,t}=\frac{\lambda}{\sigma\,\rho}\,\nabla^2\,T$$

where $\lambda$ is the thermal conductivity, $\sigma$ the material's specific heat capacity and $\rho$ its mass density. You need two things:

1. To come up with a discrete time approximation to the above equation, and decide which of several discrete time methods works for you: these are discussed in the "Numerical Solution of the Convection–Diffusion Equation" Wikipedia page. The Crank-Nikolson method is the one that most people end up settling for, but the implicit Euler method can also be made numerically stable;

2. You need to decide how to model your boundaries and thus the shape of your modelled region and the boundary conditions. For example: is there heat flux across the boundary; if not, then you impose $(\nabla\,T)\cdot\vec{n}$ there (where $\vec{n}$ is the normal to the surface. Another alternative: perhaps you'll decide your boundaries are constant temperature boundaries.

If you model a big, cubic region, then I suggest that another numerical method is to build your solution up from eigenfunctions for the system: suppose we have a cuboid of sidelengths $L_x,\,L_y,\,L_z$. Then standard separation of variables techniques shows you that the following are solutions of the equation:

$$T_{n_x,\,n_y,\,n_z}(x,\,y,\,z,\,t)=\cos\left(n_x\frac{\pi\,x}{L_x}\right)\,\cos\left(n_y\frac{\pi\,y}{L_y}\right)\,\cos\left(n_z\frac{\pi\,z}{L_z}\right)\,\exp\left(-\pi^2\left(\frac{n_x^2}{L_x^2}+\frac{n_y^2}{L_y^2}+\frac{n_z^2}{L_z^2}\right)\frac{\sigma\,\rho}{\lambda}\,t\right)$$

where $n_x,\,n_y,\,n_z$ are positive integers. You then assume your solution is made up of the sum of a finite number of these basic solutions, and numerically adjust the weighting co-efficients in the sum for minimum square error between the sum at $t=0$ and your assumed initial conditions. Then you can work out the temperature at any point from your sum. The above are basic solutions if you assume no heat flux across the cube sides: you would replace the $\cos$ functions with $\sin$ if your assumption was that the boundary temperatures were held constant.

This paper here gives more detail on the last method. I have used the last method to build a very satisfactory heat diffusion simulator for a laser heating problem I needed to think about.

Because the equation is linear, any superposition of solutions is also a solution. A general solution in the cubic region is:

$$T(x,\,y,\,z,\,t) = T_0 + \sum\limits_{n_x>0,\,n_y>0,\,n_z>0} \alpha_{n_x,\,n_y,\,n_z}\,T_{n_x,\,n_y,\,n_z}(x,\,y,\,z,\,t)$$

• what are the nx ny nz variables? – treasurewizard Nov 1 '14 at 19:24
• @treasurewizard They are positive integers. You sum the solutions up by the formula at the end of my changed answer. You then find the "superposition weights" $\alpha_{n_x,\,n_y,\,n_z}$ by linear regression: there are standard algorithms for doing this in software. Singular value decomposition works wonderfully, but there are easier methods. – WetSavannaAnimal Nov 1 '14 at 22:57
• The analytic solutions are definitely good to understand. But it's also worth considering numerical methods (finite difference is great for heat conduction). They're quick to code/run and they can be easily expanded to handle non-linear problems and complex geometry. – user3823992 Nov 2 '14 at 21:40