Partial differential equation with initial condition for time derivative

I am trying to solve the PDE

\begin{align} u_{tt} - u_{xx} + 2u &= 0 \end{align}

where $$0 \leq x \leq \pi, \ t \geq 0$$. The initial conditions are

$$u(x,0) = 0, \quad u_t(x,0) = \frac{x}{\pi}$$

and the boundary conditions are

$$u_x(0,t) = 0, \quad u_x(\pi,t) = 0$$

I am trying to solve using separation of variables. Making the ansatz

$$u(x,t) = F(x)G(t)$$

after substitution I get

$$\frac{F''(x)-2F(x)}{F(x)} = \frac{\ddot{G}(t)}{G(t)}=-n^2-2$$

I get finally a solution of the form

$$u(x,t)=\sum_{n=1}^{\infty} A_n \cos(nx) \sin(\sqrt{n^2+2}t)$$

Now I still have to comply with the initial condition for the time derivative

$$u_t(x,0) = \frac{x}{\pi}$$

This implies

$$u(x,t)=\sum_{n=1}^{\infty} A_n \cos(nx) \sqrt{n^2+2} = \frac{x}{\pi}$$

But $$x/\pi$$ is an odd function, so it can not be represented by a sum of cosine functions. What did I do wrong?

• How did you get a cosine for the spatial eigenfunction? Dirichlet boundary conditions implies $F(x) = \sin(nx)$. From your series solution, you can check yourself that $$u(0,t) = \sum A_{n} \cdot 1 \cdot \sin(\sqrt{n^{2} + 2t}) \ne 0$$ and similarly for $u(\pi, t)$. Aug 5, 2020 at 23:20
• I made a typo in the boundary conditions. I corrected it in the mean time. As you see the partial derivatives to $x$ should be 0. That is why I have a cosine. Still the same problem... Aug 6, 2020 at 0:05
• You have a half range series, not a full range (i.e $x \in [0, \pi]$ not $x \in [-\pi, \pi]$), hence the cosine series for an odd function exists. Aug 6, 2020 at 0:56
• Of course, $A_n = \frac{2}{\pi} \int_{0}^{\pi} \cos(nx) \frac{x}{\sqrt{n^2 + 1}} {\mathrm{d}x}$ . Thanks. Aug 6, 2020 at 2:34

$$\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,} \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace} \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack} \newcommand{\dd}{\mathrm{d}} \newcommand{\ds}[1]{\displaystyle{#1}} \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,} \newcommand{\ic}{\mathrm{i}} \newcommand{\mc}[1]{\mathcal{#1}} \newcommand{\mrm}[1]{\mathrm{#1}} \newcommand{\pars}[1]{\left(\,{#1}\,\right)} \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,} \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$$ \begin{align} &\mbox{Lets}\ \mrm{u}_{x}\pars{x,t} = \sum_{n = 1}^{\infty}a_{n}\pars{t}\sin\pars{nx}\ \mbox{which already satisfies}\ \mrm{u}_{x}\pars{0,t} = \mrm{u}_{x}\pars{\pi,t} = 0. \\[5mm] &\ \mbox{Then,}\ \mrm{u}\pars{x,t} = -\sum_{n = 1}^{\infty}a_{n}\pars{t}\,{\cos\pars{nx} \over n} + \mrm{f}\pars{t}. \\ &\ \mrm{f}\pars{t}\ \mbox{is a time dependent }\ arbitrary\ \mbox{function ( for the time being ).} \end{align}

$$\ds{\mrm{u}\pars{x,t}}$$ must satisfy the differential equation. Namely, \begin{align} &0 = \bracks{-\sum_{n = 1}^{\infty}\ddot{a}_{n}\pars{t}\,{\cos\pars{nx} \over n} + \ddot{\mrm{f}}\pars{t}} - \bracks{\sum_{n = 1}^{\infty}a_{n}\pars{t}n\cos\pars{nx}} \\[5mm] &\ + 2\bracks{-\sum_{n = 1}^{\infty}a_{n}\pars{t}\,{\cos\pars{nx} \over n} + \mrm{f}\pars{t}} \end{align} Integrating both sides over $$\ds{\pars{0,\pi}} \implies \ddot{\mrm{f}}\pars{t} + 2\,\mrm{f}\pars{t} = 0 \implies \mrm{f}\pars{t} = A\sin\pars{\root{2}t} + B\cos\pars{\root{2}t}$$. $$\ds{A\ \mbox{and}\ B}$$ are constants.

Similarly, integrate after multiplying both sides for a factor $$\ds{\cos\pars{nx}}$$ to get \begin{align} &\ddot{a}_{n}\pars{t} + \pars{n^{2} + 2}a_{n}\pars{t} = 0 \\ &\ \implies a_{n}\pars{t} = a_{n}\pars{0}\cos\pars{\root{n^{2} + 2}t} + \dot{a}_{n}\pars{0}\,{\sin\pars{\root{n^{2} + 2}t} \over \root{n^{2} + 2}} \end{align} The general solution becomes: \begin{align} \mrm{u}\pars{x,t} & = -\sum_{n = 1}^{\infty}\bracks{a_{n}\pars{0}\cos\pars{\root{n^{2} + 2}t} + \dot{a}_{n}\pars{0}\,{\sin\pars{\root{n^{2} + 2}t} \over \root{n^{2} + 2}}}\,{\cos\pars{nx} \over n} \\ & + A\sin\pars{\root{2}t} + B\cos\pars{\root{2}t} \end{align} Also, $$0 = \mrm{u}\pars{x,0} = -\sum_{n = 1}^{\infty}a_{n}\pars{0}\,{\cos\pars{nx} \over n} + B \implies a_{n}\pars{0} = B = 0$$ The general solution is reduced to \begin{align} \mrm{u}\pars{x,t} & = -\sum_{n = 1}^{\infty} \dot{a}_{n}\pars{0}\,{\sin\pars{\root{n^{2} + 2}t} \over \root{n^{2} + 2}}\,{\cos\pars{nx} \over n} + A\sin\pars{\root{2}t} \end{align} In addition, \begin{align} \mrm{u}_{t}\pars{x,0} & = {x \over \pi} = -\sum_{n = 1}^{\infty} \dot{a}_{n}\pars{0}\,{\cos\pars{nx} \over n} + \root{2}A \end{align} Integrating both sides over $$\ds{\pars{0,\pi} \implies {\pi \over 2} = \root{2}A\pi \implies A = {\root{2} \over 4}}$$. Also, \begin{align} &\int_{0}^{\pi}{x \over \pi}\,\cos\pars{nx}\,\dd x = -\,{\pi \over 2n}\dot{a}_{n}\pars{0} \implies {\pars{-1}^{n} - 1 \over n^{2}\pi} = -\,{\pi \over 2n}\dot{a}_{n}\pars{0} \\[5mm] &\ \implies \dot{a}_{n}\pars{0} = {2 \over \pi^{2}}\,{1 - \pars{-1}^{n} \over n} \end{align} Finally, \begin{align} \mrm{u}\pars{x,t} & = -\sum_{n = 1}^{\infty} {2 \over \pi^{2}}\,{1 - \pars{-1}^{n} \over n}\,{\sin\pars{\root{n^{2} + 2}t} \over \root{n^{2} + 2}}\,{\cos\pars{nx} \over n} + {\root{2} \over 4}\,\sin\pars{\root{2}t} \\[5mm] & = \color{red}{-\,{4 \over \pi^{2}}\sum_{n = 0}^{\infty} {1 \over \pars{2n + 1}^{2}}\,{\sin\pars{\root{\bracks{2n + 1}^{2} + 2}t} \over \root{\bracks{2n + 1}^{2} + 2}}\cos\pars{\bracks{2n + 1}x}} \\[2mm] &\ \color{red}{+ {\root{2} \over 4}\,\sin\pars{\root{2}t}} \end{align}