Solve 1D Heat Equation by Separation of Variables Solve by separation of variables
$$\frac{\partial u}{\partial t}=k\frac{\partial^2 u}{\partial x^2}$$
given intitial conditions:
$$\frac{\partial u}{\partial x}=0 \text{ at } x=a \text{ and } x=-a, \forall t\geq 0;$$
$$u \text{ is bounded for }-a\leq x\leq a\text{ as }t\rightarrow\infty;$$
$$u=|x|\text{ for }-a\leq x\leq a\text{ at }t=0.$$
So I've been stuck on this problem for a few days now. I've tried a bunch of different things but I'm unsure of how to properly approach the problem. I have the answer, but it's unclear on how to get there. I originally thought that I could start with the general solution of the heat equation which is already known.
$$u(x,t)=X(x)T(t)=(A\cos{wx}+B\sin{wx})Ce^{-w^2kt}$$
I started to play with initial conditions using this solution and ultimately I got with $B^*=BC, A^*=AC$ that $B^*=A^*\tan{wa}$ which lead to a weird $u$ that was defined on an interval using the boundary conditions. I couldn't gather much information.
After reviewing notes and the text, "Geoff Stephenson - PDE's for Scientists & Engineers, Ch. 4.3". I thought it would be wise to assume a solution of the form $u(x,t)=v(x)+w(x,t)$ where $\frac{\partial^2 v}{\partial x^2}=0$ and $w(x,t)=X(x)T(t)$. Using boundary conditions, this lead me to
$$u(x,0)=|x|\implies |x|=v(x)+w(x,0)\implies v(x)=|x|-w(x,0)$$
From this can I then say $u(x,t)=|x|-w(x,0)+w(x,t)$?
I can't figure this stuff out for the life of me.
 A: The basic separated solutions $u(x,t)=X(x)\,T(t)$ that satisfy the given boundary conditions $u_x(\pm a,t)=0$ (or $X'(\pm a)=0$, in other words) are
$$
u(x,t) = 1
$$
and
$$
u(x,t) = \sin(\omega x) \, e^{-k \omega^2 x}
,\quad\text{where}\quad
\omega a \in \left\{ \frac{\pi}{2}, \frac{3\pi}{2}, \frac{5\pi}{2}, \ldots \right\}
,
$$
and
$$
u(x,t) = \cos(\omega x) \, e^{-k \omega^2 x}
,\quad\text{where}\quad
\omega a \in \bigl\{ \pi, 2\pi, 3\pi, \ldots \bigr\}
,
$$
and what you have to do is to find a linear combination of all these (i.e., a Fourier-type series) which satisfies the initial condition $u(x,0)=|x|$ for $|x|\le a$. Since $|x|$ is an even function, there will be no sine terms, so you'll get a solution of the form
$$
u(x,t) = C + \sum_{n=1}^{\infty} A_n \cos\left(\frac{n \pi x}{a}\right) \, e^{-k (n^2 \pi^2 /a^2) \, t}
$$
where the coefficients $C$ and $A_n$ ($n=1,2,3,\ldots$) are such that
$$
|x| = C + \sum_{n=1}^{\infty} A_n \cos\left(\frac{n \pi x}{a}\right)
,\quad
|x|\le a.
$$
Can you take it from there?
A: Start by assuming solutions of the form $u(x,t)=X(x)T(t)$, where
$$
                     X'(-a)=0=X'(a).
$$
Then there is a separation constant $C$ such that
$$
                   \frac{T'(t)}{kT(t)}=-C,\;\; -C=\frac{X''(x)}{X(x)},\\
                       X'(-a)=0=X'(a).
$$
I have chosen $-C$ because the only solution of $X''/X=C$ where $C > 0$ and $X'(-a)=0=X'(a)$ is $X\equiv 0$. To further normalize the solutions $X$, we may assume that $X(-a)=1$ (or, alternatively, $X(a)=1$) because $X''+CX=0$ has only the trivial solution if $X(-a)=X'(-a)=0$. With this normalization,
$$
               X(x)=\cos(\sqrt{C}(x+a))
$$
In order for this solution to satisfy $X'(a)=0$, it is necessary and sufficient that $\sin(2\sqrt{C}a)=0$, which gives
$$
       2\sqrt{C}a=\pi,2\pi,3\pi,\cdots \\
             C=\frac{\pi^2}{4a^2},4\frac{\pi^2}{4a^2},9\frac{\pi^2}{4a^2},\cdots.
$$
Therefore, the solutions in $x$ are
$$
             X_n(x)=\cos\left(\frac{n\pi}{2a}(x+a)\right),\;\; n=0,1,2,3,\cdots.
$$
The corresponding solutions in $t$ satisfy
$$
               T'(t)=-C_n kT(t)=-\frac{kn^2\pi^2}{4a^2}T(t) \\
                       T_n(t) = D_n\exp\left(-\frac{kn^2\pi^2}{4a^2}t\right)
$$
So, the full solution is
$$
        u(x,t) = \sum_{n=0}^{\infty}D_n\cos\left(\frac{n\pi}{2a}(x+a)\right)\exp\left(-\frac{kn^2\pi^2}{4a^2}t\right)
$$
The constants $D_n$ are determined by the initial condition and the orthogonality of the $\cos$ terms:
$$
             u(x,0)=\sum_{n=0}^{\infty}D_n\cos\left(\frac{n\pi}{2a}(x+a)\right) \\
               |x| = \sum_{n=0}^{\infty}D_n\cos\left(\frac{n\pi}{2a}(x+a)\right)  \\
           \int_{-a}^{a}|x|\cos\left(\frac{n\pi}{2a}(x+a)\right)dx
   = D_n\int_{-a}^{a}\cos^2\left(\frac{n\pi}{2a}(x+a)\right)^2dx
$$
