# Solution to heat equation with changing boundary conditions

I am attempting to solve a homogeneous heat equation

$$$$u_t = \alpha^2 u_{xx},$$$$ with an initial temperature $$u_0$$, and time-varying boundary conditions $$u(0,t) = u(L,t) = u_s(t)$$. The challenge is that the function $$u_s (t)$$ isn't a continuous function that can be expressed neatly, but rather a series of temperatures given for every minute. I followed the method laid out here

and got the result

$$$$u_c(t) = u_s (t) - \frac{4}{\pi} \sum_{n=0}^\infty \frac{(-1)^n}{2 n + 1} e^{- (2n + 1)^2 \pi^2 \alpha^2 / L^2 t} \left( \int_0^t e^{(2n + 1)^2 \pi^2 \alpha^2 / L^2 \tau} u_s ' (\tau) d\tau + u_s (0) - u_0 \right),$$$$

hoping that I could still approximate the integral with a sum like so

$$$$u_c(t) \approx u_s (t) - \frac{4}{\pi} \sum_{n=0}^\infty \frac{(-1)^n}{2 n + 1} e^{- 60 (2n + 1)^2 \pi^2 \alpha^2 / L^2 t} \left( \sum_{m=0}^{t - 1} e^{60(2n + 1)^2 \pi^2 \alpha^2 / L^2 m} \Delta u_s^m + u_s (0) - u_0 \right), \quad \Delta u_s^m \equiv u_s^{m+1} - u_s^m.$$$$ ($$m$$ represents minutes, and in any real calculation $$t$$ would be floored down to the nearest integer) I am able to compare the above result to measured values for the temperature, and it does not hold up at all.

My question is then, do anyone know of a better way to handle boundary conditions that are put in by hand every minute? Ultimately, I would like to be able to extract the size $$L$$, which is why I am not doing this numerically.

If you would like to see my derivation, I post it below:

We have

$$$$u_t = \alpha^2 u_{xx},$$$$ with boundary and initial conditions

\begin{align*} u(x,0) & = f(x), \quad u(0,t) = u(L,t) = u_s (t)\\ f(0) & = f(L) = u_s(0), \quad f(0 and assume

$$$$s_{xx}(x,t) = 0,$$$$ so that

$$$$s(x,t) = u_s (t).$$$$ Then we get the inhomogenous equation

$$$$v_t = \alpha^2 v_{xx} - u_s'.$$$$ The homogeneous equation is solved by

$$$$v(x,t) = \sum_{n=1}^\infty T_n (t) X_n (x), \quad X_n (x) = \sin \left( \frac{n \pi x}{L} \right).$$$$ For the inhomogeneous equation, we make the ansatz

$$$$u'_s (t) = - \sum_{n=1}^\infty Q_n (t) X_n (x),$$$$ so that the heat equation becomes

$$$$\sum_{n=1}^\infty \left( T_n' (t) + \lambda_n T_n (t) - Q_n (t) \right) X_n (x) = 0, \quad \lambda_n = \left( \frac{n \pi \alpha}{L} \right)^2,$$$$ which means that

$$$$T_n (t) = e^{-\lambda_n t} \int_0^t e^{\lambda_n \tau} Q_n (\tau) d \tau + C_n e^{-\lambda_n t}.$$$$ The $$C_n$$'s are found by checking the initial conditions

$$$$v(x,0) = u(x,0) - s(x,0) = u_0 - u_s (0) = \sum_{n=1}^\infty T_n (0) X_n (x) = \sum_{n=1}^\infty C_n X_n (x),$$$$ so

$$$$C_n = \frac{2 \left( 1 - (-1)^n \right) \left( u_0 - u_s (0) \right)}{n \pi}.$$$$ $$Q_n (t)$$ is found from the orthogonality of the $$X_n (x)$$'s

$$$$Q_n (t) = 2 \frac{(-1)^n - 1}{n \pi} u_s' (t),$$$$ or, since only terms with $$n$$ odd are non-zero,

\begin{align*} C_n & = \frac{4}{(2n+1) \pi} \left( u_0 - u_s (0) \right),\\ Q_n (t) & = - \frac{4}{(2 n + 1) \pi} u_s ' (t). \end{align*} Then

$$$$T_n (t) = - \frac{4}{(2 n + 1) \pi} e^{- (2n + 1)^2 \pi^2 \alpha^2 / L^2 t} \left( \int_0^t e^{(2n + 1)^2 \pi^2 \alpha^2 / L^2 \tau} u_s ' (\tau) d\tau + u_s(0) - u_0 \right)$$$$ and

$$$$v(x,t) = - \frac{4}{\pi} \sum_{n=0}^\infty \frac{1}{(2 n + 1) \pi} e^{- (2n + 1)^2 \pi^2 \alpha^2 / L^2 t} \left( \int_0^t e^{(2n + 1)^2 \pi^2 \alpha^2 / L^2 \tau} u_s ' (\tau) d\tau + u_s(0) - u_0 \right) \sin \left( \frac{(2n+1) \pi x}{L} \right).$$$$ The temperature is then

$$$$u(x,t) = u_s (t) - \frac{4}{\pi} \sum_{n=0}^\infty \frac{1}{(2 n + 1) \pi} e^{- (2n + 1)^2 \pi^2 \alpha^2 / L^2 t} \left( \int_0^t e^{(2n + 1)^2 \pi^2 \alpha^2 / L^2 \tau} u_s ' (\tau) d\tau + u_s(0) - u_0 \right) \sin \left( \frac{(2n+1) \pi x}{L} \right).$$$$ In the core the temperature is

$$$$u_c(t) = u_s (t) - \frac{4}{\pi} \sum_{n=0}^\infty \frac{(-1)^n}{2 n + 1} e^{- (2n + 1)^2 \pi^2 \alpha^2 / L^2 t} \left( \int_0^t e^{(2n + 1)^2 \pi^2 \alpha^2 / L^2 \tau} u_s ' (\tau) d\tau + u_s (0) - u_0 \right).$$$$ Numerically, this is

$$$$u_c(t) \approx u_s (t) - \frac{4}{\pi} \sum_{n=0}^\infty \frac{(-1)^n}{2 n + 1} e^{- 60 (2n + 1)^2 \pi^2 \alpha^2 / L^2 t} \left( \sum_{m=0}^{t - 1} e^{60(2n + 1)^2 \pi^2 \alpha^2 / L^2 m} \Delta u_s^m + u_s (0) - u_0 \right), \quad \Delta u_s^m \equiv u_s^{m+1} - u_s^m.$$$$

• "[Does] anyone know of a better way to handle boundary conditions that are put in by hand every minute?" My answer would be full-on numerical simulation, to be honest. Nov 6 '20 at 14:11
• Thank you for comment. I did solve it with a forward Euler scheme where the lower bound on the mesh size is fixed by the 1 min time steps. It wasn't super accurate, but that could be down to uncertainties in other parameters. I probably should have mentioned this, but the ultimate goal of this calculation is to be able to extract the size L, and the numerical calculation would not allow that. I'll edit my post to make this point clear. Nov 6 '20 at 15:01
• Is the temperature changed in steps, or is it changed linearly over each time interval? Nov 6 '20 at 15:01
• @ChetMiller It is changed in steps. The idea is that at any point during the heating, someone could turn on a knob to increase the surrounding temperature. Nov 6 '20 at 15:04

If the temperature is changes in steps, then you can obtain the solution by linear superposition. Let the solution for a unit step temperature change at time zero (with 0 internal initial temperature) be U(x,t), and let the boundary temperature change at time $$t_j$$ be $$\Delta u_{sj}$$, then the solution for your situation will be $$u(x,t)=u_0+\sum_j{\Delta u_{sj}U(x,t-t_j)}$$This is essentially the solution you have written for step changes in temperature.