# Solving the heat equation

I have the heat equation $$\frac{\partial u}{\partial t}=\frac{\partial^2u}{\partial x^2}$$ where $0\leq t<\infty$ and $0\leq x\leq1$

The Boundary conditions are $u(0,t)=0$ and $u(1,t)=1$ with initial condition $u(x,0)=x+sin(\pi x)$

I assume the solution is of the form $u=u(x,t)=X(x)T(t)$ I find the respective derivatives of $u$ and substitute them into the original heat equation to get $$\frac{T'}{T}(t)=\frac{X''}{X} (x)=k$$

I have two Ode's $$T'=KT$$ and $$X''=KX$$

I now look at three different cases.

Case 1. K=0 My solutions say $X(x)=1$ and $T(t)=1$. Where do they come from?

For case 2. I have $K=-p^2<0$ The solution I have is $$X(x)=Acos(px)+Bsin(px)$$ and then $X(x)=sin(\pi nx)$and $T(t)=e^{-\pi^2n^2t}$ How do I get this solution?

For case 3. I have $K=p^2>0$. This gives me $X(x)=Ae^{px}+Be^{-px}$ whic gives me $X(x)=0$ and $T(t)=e^{p^2 t}$ Where do these come from?

The rule of thumb is that you try to substitute appropriate general functions in your ODEs and thus determine the solution. For more detail see derivation of characteristic equation of a linear differential equation.

As for the cases of different values of $K$, the answers can be derived using common sense.

First, we take a notion of the boundary and initial conditions. You have inhomogeneous Dirichlet BCs, therefore the general solution of your equation can be represented as a sum of the general solution of the same equation with homogeneous BCs and a particular solution satisfying inhomogeneous BCs. The separation of variables is applied to find the general solution of the equation with homogeneous BCs firs. See this webpage for details.

Since $u(x,t) = X(x)T(t)$, we have $$u(0,t) = X(0)T(t) = 0 \implies X(0) = 0.$$

Second, the answers for the different cases of $K$ can be derived using common sense:

1. $K = 0 \implies$

(1.a) $T' = KT \implies T' = 0 \implies T(t) \equiv c - \text{ const.}$ Without loss of generality we can assume $c=1$, i.e. that $T(t) \equiv 1$.

(1.b) $$X'' = KX \iff X'' =0 \implies X(x) = ax + b, \quad a,b \in \mathbb{R}\\ X(x)T(0) = 1 \iff a\cdot 1 = 1 \implies a = 1 \implies X(x) = x$$

2. For simplicity, I am going to explain the solution of homogeneous Boundary Conditions problem, i.e. I assume $X(0)=X(1) = 0$. For generalization to inhomogeneous BC case see this link.

$K = -p^2 <0 \implies$

(2.a) $T' = KT \implies T' = -p^2 T \implies T(t) = ce^{-p^2 t}, \quad c \text{ is a const.},$ since exponent is the only (nontrivial) function whose derivative equals the function itself multiplied by a constant: $$\frac{d}{dt} \Big(c e^{-p^2 t} \Big) = -p^2 c e^{-p^2 t}.$$

(2.b) $X'' = KX \implies K'' = -p^2 K \implies X(x) = a \sin px + b \cos px,$ since sine and cosine are the only (nontrivial) functions whose second derivatives equal the functions themselves multiplied by a negative squared constant, e.g. $$\frac{d^2}{dx^2} \Big(a \sin px + b \cos px \Big) = \frac{d}{dx} \Big(a\,p \cos px - b\, p \sin px \Big) = -a\, p^2 \sin px - b\,p^2 \cos px = -p^2 \big( a\sin px + b \cos px \big).$$ Applying (homogeneous) boundary conditions, we have $$X(0) = 0 \implies a \sin 0 + b\cos 0 = a\cdot 0 + b \cdot 1 = 0 \implies b =0 ,\\ X(1) = 0 \implies a \sin p + 0 \cdot \cos pi = a\sin p = 0 \implies p = \pi n, n \in \mathbb{N}.$$ Therefore $u(x,t) = a \sin (\pi n x) e^{-\pi^2 n^2 t} .$ Applying initial conditions for the homogeneous problem, we get $$u(x,0) =\sin \pi x \implies a \sin (\pi n x) e^{-\pi^2 n^2 0} = a \sin (\pi n x) = \sin \pi x \implies a=n=1,$$ so we finally write $$u(x,t) = \sin (\pi n x) e^{-\pi^2 n^2 t}$$

3. Again, I assume $X(0)=X(1) = 0$. For generalization to inhomogeneous BC case see this link.

$K = p^2 >0 \implies$

(3.a) $T' = KT \implies T' = p^2 T \implies T(t) = ce^{p^2 t}, \ c -$const.

(3.b) $X'' = KX \implies X'' = p^2 X \implies X = a e^{px} + be^{-px}, \quad a,b - \text{ consts}$. This is because exponent is the only function satisfying $X'' = KX$ ODE, because $$\frac{d^2}{dx^2} \Big(a e^{px} + be^{-px} \Big) = \frac{d}{dx} \Big(a\,p e^{px} - b \, p e^{-px}\Big) = a\, p^2 e^{px} + b \, p^2e^{-px} = p^2 \big(a e^{px} + be^{-px} \big).$$ Apply BC: $$X(0) = 0 \implies a e^{0} + be^{0} = 0 \implies a+b = 0 \implies a = -b \\ X(1) = 0 \implies a e^{p} + be^{-p} = 0 \implies a \big( e^{p} - e^{-p}\big) = 0 \implies e^{-p} = e^p \implies p=0,$$ so that $X(x) = a + b = 2a$, and thus $u(x,t) = 2a ce^{p^2 t }$.

Apply IC for homogeneous problem: $$X(x)T(0) = 0 \implies X(x) = 0$$

Applying inhomogeneous BC and IC you can show that $2 ac = 1 \implies T(t) = e^{p^2 t }$ for the case $K =p^2>0$.