# Heat equation with non-homogeneous boundary conditions

I am struggling with the following problem and am looking for some guidance.

Find the solution to the 1-D heat equation given the following conditions:

A sphere with radius 0 < r < a with initial temperature f[r] and surface temperature Phi[t].z The boundary conditions for u[r, t] are:

u[0, t] == 0
u[a, t] == a Phi[t]


The initial condition is:

u[r, 0] == r f[r]

heqn = D[u[r, t], t] == k*D[u[r, t], {r, 2}];
bc1 = u[0, t] == 0;
bc2 = u[a, t] == a*[Phi][t];
ic = u[r, 0] == r*f[r];
sol = DSolve[{heqn, ic, bc1, bc2}, u[r, t], {r, t}];


Any suggestions?

• Mathematica DSolve can't solve heat PDE in 1D with boundary conditions that is time dependent. ps. why do you write [Phi][t] instead of Phi[t] ? Or is this a copy/paste thing? Apr 16, 2019 at 2:43
• Sorry about that. It was a copy and paste error. Is there another function you would suggest? Apr 16, 2019 at 3:20
• I suppose a "by hand" solution would be helpful. If you're willing, that is. It would be appreciated. Apr 16, 2019 at 3:37

I suppose a "by hand" solution would be helpful. If you're willing, that is. It would be appreciated

Ok, here it is

Solve $$$$u_{t}=ku_{rr}\qquad t>0,0 With boundary conditions \begin{align*} u\left( 0,t\right) & =0\\ u\left( a,t\right) & =a\phi\left( t\right) \end{align*}

And initial conditions $$u\left( r,0\right) =rf\left( r\right)$$ Since the boundary conditions are not homogeneous, the first step is to convert them to homogeneous. This is done using a reference function which needs to only satisfy the boundary conditions. This reference function can be seen to be $$v\left( r,t\right) =r\phi\left( t\right)$$. Now we write $$u\left( r,t\right) =w\left( r,t\right) +v\left( r,t\right)$$ Where $$w\left( r,t\right)$$ satisfies the PDE but with homogeneous B.C. Substituting the above into (1) gives \begin{align} w_{t}\left( r,t\right) +r\phi^{\prime}\left( t\right) & =kw_{rr} \nonumber\\ w_{t}\left( r,t\right) & =kw_{rr}-r\phi^{\prime}\left( t\right) \tag{2} \end{align} With boundary conditions \begin{align*} w\left( 0,t\right) & =0\\ w\left( a,t\right) & =0 \end{align*} The solution to the homogeneous PDE $$w_{t}\left( r,t\right) =kw_{rr}$$ with the above boundary conditions is easily found and known. The eigenvalues are $$\lambda_{n}=\left( \frac{n\pi}{a}\right) ^{2},n=1,2,\cdots$$ and eigenfunctions $$\Phi_{n}\left( r\right) =\sin\left( \sqrt{\lambda_{n} }r\right)$$. Let the solution to (2), using eigenfunction expansion be $$$$w\left( r,t\right) =\sum_{n=1}^{\infty}C_{n}\left( t\right) \Phi _{n}\left( r\right) \tag{2A}$$$$ Substituting the above back into (2) gives $$$$\sum_{n=1}^{\infty}C_{n}^{\prime}\left( t\right) \Phi_{n}\left( r\right) =k\sum_{n=1}^{\infty}C_{n}\left( t\right) \Phi_{n}^{\prime\prime}\left( r\right) -\sum_{n=1}^{\infty}q_{n}\left( t\right) \Phi_{n}\left( r\right) \tag{3}$$$$ Where $$q_{n}\left( t\right)$$ are the Fourier coefficients of $$r\phi ^{\prime}\left( t\right)$$ which are found by $$r\phi^{\prime}\left( t\right) =\sum_{n=1}^{\infty}q_{n}\left( t\right) \Phi_{n}\left( r\right)$$ Applying orthogonality using $$\Phi_{n}\left( r\right)$$ gives \begin{align*} \int_{0}^{a}r\phi^{\prime}\left( t\right) \Phi_{m}\left( r\right) dr & =\int_{0}^{a}\sum_{n=1}^{\infty}q_{n}\left( t\right) \Phi_{n}\left( r\right) \Phi_{m}\left( r\right) dr\\ & =\sum_{n=1}^{\infty}q_{n}\left( t\right) \int_{0}^{r}\Phi_{n}\left( r\right) \Phi_{m}\left( r\right) dr \end{align*} But $$\int_{0}^{a}\Phi_{n}\left( r\right) \Phi_{m}\left( r\right) dr=\int_{0}^{a}\sin\left( \frac{n\pi}{a}r\right) \sin\left( \frac{m\pi} {a}r\right) dr=\frac{a}{2}$$ for $$n=m$$ only, and the above becomes $$\frac{2}{a}\int_{0}^{a}r\phi^{\prime}\left( t\right) \Phi_{m}\left( s\right) dr=q_{m}\left( t\right)$$ Substituting the above back into (3) gives $$\sum_{n=1}^{\infty}C_{n}^{\prime}\left( t\right) \Phi_{n}\left( r\right) =k\sum_{n=1}^{\infty}C_{n}\left( t\right) \Phi_{n}^{\prime\prime}\left( r\right) -\sum_{n=1}^{\infty}\left( \frac{2}{a}\int_{0}^{a}r\phi^{\prime }\left( t\right) \Phi_{m}\left( r\right) dr\right) \Phi_{n}\left( r\right)$$ But $$\Phi_{n}^{\prime\prime}\left( r\right) =-\lambda_{n}\Phi_{n}\left( r\right)$$ and above simplifies to \begin{align*} \sum_{n=1}^{\infty}C_{n}^{\prime}\left( t\right) \Phi_{n}\left( r\right) +k\sum_{n=1}^{\infty}C_{n}\left( t\right) \lambda_{n}\Phi_{n}\left( r\right) & =-\sum_{n=1}^{\infty}\left( \frac{2}{a}\int_{0}^{a} r\phi^{\prime}\left( t\right) \Phi_{m}\left( r\right) dr\right) \Phi _{n}\left( r\right) \\ C_{n}^{\prime}\left( t\right) +kC_{n}\left( t\right) \lambda_{n} & =-\frac{2}{a}\int_{0}^{a}r\phi^{\prime}\left( t\right) \Phi_{m}\left( r\right) dr\\ & =-\frac{2}{a}\phi^{\prime}\left( t\right) \int_{0}^{a}r\sin\left( \frac{n\pi}{a}r\right) dr\\ & =-\frac{2}{a}\phi^{\prime}\left( t\right) \frac{\left( -1\right) ^{n+1}a^{2}}{n\pi}\\ & =-2a\phi^{\prime}\left( t\right) \frac{\left( -1\right) ^{n+1}}{n\pi} \end{align*} This is first order ODE in $$C\left( t\right)$$. The solution is $$C_{n}\left( t\right) =e^{-k\lambda_{n}t}C_{n}\left( 0\right) +2ae^{-k\lambda_{n}t}\frac{\left( -1\right) ^{n+1}}{n\pi}\int_{0}^{t} \phi^{\prime}\left( \tau\right) e^{k\lambda_{n}\tau}d\tau$$ From (2A) $$w\left( r,t\right) =\sum_{n=1}^{\infty}\left( e^{-k\lambda_{n}t} C_{n}\left( 0\right) +2ae^{-k\lambda_{n}t}\frac{\left( -1\right) ^{n+1} }{n\pi}\int_{0}^{t}\phi^{\prime}\left( \tau\right) e^{k\lambda_{n}\tau} d\tau\right) \sin\left( \frac{n\pi}{a}r\right)$$ Hence \begin{align} u\left( r,t\right) & =w\left( r,t\right) +v\left( r,t\right) \nonumber\\ & =\sum_{n=1}^{\infty}\left( e^{-k\lambda_{n}t}C_{n}\left( 0\right) +2ae^{-k\lambda_{n}t}\frac{\left( -1\right) ^{n+1}}{n\pi}\int_{0}^{t} \phi^{\prime}\left( \tau\right) e^{k\lambda_{n}\tau}d\tau\right) \sin\left( \frac{n\pi}{a}r\right) +r\phi\left( t\right) \tag{4} \end{align} At $$t=0$$ the above becomes \begin{align*} rf\left( r\right) & =\sum_{n=1}^{\infty}C_{n}\left( 0\right) \sin\left( \frac{n\pi}{a}r\right) +r\phi\left( 0\right) \\ \sum_{n=1}^{\infty}C_{n}\left( 0\right) \sin\left( \frac{n\pi}{a}r\right) & =r\left( f\left( r\right) -\phi\left( 0\right) \right) \end{align*} Hence $$C_{n}\left( 0\right)$$ is the Fourier sine coefficients of $$\ r\left( f\left( r\right) -\phi\left( 0\right) \right)$$ \begin{align*} \frac{a}{2}C_{n}\left( 0\right) & =\int_{0}^{a}r\left( f\left( r\right) -\phi\left( 0\right) \right) \sin\left( \frac{n\pi}{a}r\right) dr\\ C_{n}\left( 0\right) & =\frac{2}{a}\int_{0}^{a}r\left( f\left( r\right) -\phi\left( 0\right) \right) \sin\left( \frac{n\pi}{a}r\right) dr \end{align*}

Substituting this into (4) gives the final solution as \begin{align*} u\left( r,t\right) & =r\phi\left( t\right) +\sum_{n=1}^{\infty}\left( e^{-k\lambda_{n}t}\left( \frac{2}{a}\int_{0}^{a}r\left( f\left( r\right) -\phi\left( 0\right) \right) \sin\left( \frac{n\pi}{a}r\right) dr\right) +2ae^{-k\lambda_{n}t}\frac{\left( -1\right) ^{n+1}}{n\pi}\int_{0}^{t} \phi^{\prime}\left( \tau\right) e^{k\lambda_{n}\tau}d\tau\right) \sin\left( \frac{n\pi}{a}r\right) \\ & =r\phi\left( t\right) +\sum_{n=1}^{\infty}\left( e^{-k\lambda_{n} t}\left( \frac{2}{a}\int_{0}^{a}r\left( f\left( r\right) -\phi\left( 0\right) \right) \sin\left( \frac{n\pi}{a}r\right) dr\right) +2a\frac{\left( -1\right) ^{n+1}}{n\pi}\int_{0}^{t}\phi^{\prime}\left( \tau\right) e^{-k\lambda_{n}\left( t-\tau\right) }d\tau\right) \sin\left( \frac{n\pi}{a}r\right) \\ & =r\phi\left( t\right) +\sum_{n=1}^{\infty}e^{-k\lambda_{n}t}\left( \frac{2}{a}\int_{0}^{a}r\left( f\left( r\right) -\phi\left( 0\right) \right) \sin\left( \frac{n\pi}{a}r\right) dr\right) \sin\left( \frac {n\pi}{a}r\right) +\sum_{n=1}^{\infty}2a\frac{\left( -1\right) ^{n+1}} {n\pi}\int_{0}^{t}\phi^{\prime}\left( \tau\right) e^{-k\lambda_{n}\left( t-\tau\right) }d\tau\sin\left( \frac{n\pi}{a}r\right) \end{align*}

Or

\begin{align*} u\left( r,t\right) & =r\phi\left( t\right) \\ & +\frac{2}{a}\sum_{n=1}^{\infty}e^{-k\lambda_{n}t}\sin\left( \frac{n\pi} {a}r\right) \left( \int_{0}^{a}r\left( f\left( r\right) -\phi\left( 0\right) \right) \sin\left( \frac{n\pi}{a}r\right) dr\right) \\ & +\frac{2a}{\pi}\sum_{n=1}^{\infty}\frac{\left( -1\right) ^{n+1}}{n} \sin\left( \frac{n\pi}{a}r\right) \int_{0}^{t}\phi^{\prime}\left( \tau\right) e^{-k\lambda_{n}\left( t-\tau\right) }d\tau \end{align*}

Where $$\lambda_{n}=\left( \frac{n\pi}{a}\right) ^{2}$$.

I can use NDSolve to verify the above solution and comparing them. But I do not have values for your a,f[r],phi[t] to do that. If you have these, I could try to do that.