Flaw in solving a PDE and Fourier Series 
*

*Consider the Laplacian equation in cylindrical coordinates with no theta $\left(~\theta~\right)$ dependence:
\begin{align}
&\mbox{So,}\quad\frac{1}{r} (r(u)_r)_r + (u)_{zz} = 0
\\[2mm]
&\mbox{subject to}\quad
\left\{\begin{array}{rcl}
u\left(r=R,z\right) & = & 1
\\
u\left(r=0,z\right) & = & \text{finite}
\\
u\left(r,z=\pm H\right) & = & 0
\end{array}\right.
\end{align}

*Using separation of variables, $u(r,z) = A(r)B(z)$, we get
$$B''=-\lambda ^2 B \\
rA'' + A' - \lambda^2 r A = 0$$

*Solving the $B(z)$ equation and imposing the boundary conditions, I get,
$$c_1 \cos(\lambda H) + c_2\sin(\lambda H) = 0 \\
c_1 \cos(\lambda H) - c_2\sin(\lambda H) = 0$$
I was told that this was incorrect, and I should be using $\sinh$ and $\cosh$ functions to this DE. My question is, why is that allowed? Aren't they non-periodic?

What am I doing wrong here, and how am I supposed to know when to use $\sin$ and $\cos$, and when to use $\sinh$ and $\cosh$ when solving PDEs?
 A: $\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{\on}[1]{\operatorname{#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}$
$
{\Large ?}:\quad\left\{\begin{array}{l}
\ds{{1 \over r}\partiald{}{r}
\bracks{r\,\partiald{\on{u}\pars{r,z}}{r}} +
\partiald[2]{\on{u}\pars{r,z}}{z} = 0}
\\[3mm]
\ds{\on{u}\pars{r,\pm H} = 0}
\\[3mm]
\left.\begin{array}{rcl}
\ds{\on{u}\pars{0,z}} & \mbox{is} & \ds{finite}.
\\[1mm]
\ds{\on{u}\pars{R,z}} & \ds{=} & \ds{1}
\end{array}\right\}
\end{array}\right.
$


*

*Lets $\ds{\on{u}\pars{r,z} \equiv
\sum_{n = 0}^{\infty}a_{n}\pars{r}
\cos\pars{k_{n}z}}$ where $\ds{k_{n} \equiv \pars{2n + 1}{\pi \over 2H}}$.

Note that
$\ds{\on{u}\pars{r,z}}$ already satisfies the boundary conditions at $\ds{z = \pm H}$ and, in addition, it exhibits the $\ds{z \mapsto -z}$ symmetry. Also,
\begin{equation}
\int_{-H}^{H}\cos\pars{k_{m}z}
\cos\pars{k_{n}z}\,\dd z = H\,\delta_{mn}
\label{1}\tag{1}
\end{equation}

*

*$\ds{\on{u}\pars{r,z}}$ must satisfy the above differential equation:
\begin{align}
&\sum_{n = 1}^{\infty}\braces{%
{1 \over r}\totald{}{r}
\bracks{r\,\totald{a_{n}\pars{r}}{r}} -
k_{n}^{2}\,a_{n}\pars{r}}\cos\pars{k_{n}z} = 0
\end{align}
Use (\ref{1}) to obtain
$\ds{{1 \over r}\totald{}{r}\bracks{r\,\totald{a_{n}\pars{r}}{r}} -
k_{n}^{2}\,a_{n}\pars{r} = 0}$

*The last equation solution is a linear combination of
$\ds{\on{J}_{0}\pars{\ic k_{n}r}\ \mbox{and}\ \on{Y}_{0}\pars{\ic k_{n}r}}$ which are
Bessel Functions.
Note that, as $\ds{r \to 0^{+}}$,
$$
\on{J}_{0}\pars{\ic k_{n}r} \to 1\quad
\mbox{and}\quad
\on{Y}_{0}\pars{\ic k_{n}r} \sim
{2 \over \pi}\ln\pars{\ic k_{n}r}.
$$
See this link.  The finite solution, when $\ds{r \to 0^{+}}$, is given by $\ds{b_{n}\on{J}_{0}\pars{\ic k_{n}r}}$ where $\ds{b_{n}}$ is a constant.

*Then,
$$
\on{u}\pars{r,z} =
\sum_{n = 0}^{\infty}
b_{n}\on{J}_{0}\pars{\ic k_{n}r}
\cos\pars{k_{n}z} 
$$

*Moreover,
$$
1 = \sum_{n = 0}^{\infty}
b_{n}\on{J}_{0}\pars{\ic k_{n}\color{red}{R}}
\cos\pars{k_{n}z}
$$
Multiply both members by $\ds{\cos\pars{k_{n}z}/H}$ and use (\ref{1}) to integrate over $\ds{z \in \pars{-H,H}}$:
\begin{align}
&\overbrace{{1 \over H}
\int_{-H}^{H}\cos\pars{k_{n}z}\dd z}
^{\ds{{4 \over \pi}\,{\pars{-1}^{n} \over 2n + 1}}}
\\[5mm] = &\
\sum_{m = 0}^{\infty}
b_{m}\on{J}_{0}\pars{\ic k_{m}R}
\underbrace{\bracks{{1 \over H}\int_{-H}^{H}
\cos\pars{k_{n}z}\cos\pars{k_{m}z}\dd z}}
_{\ds{\delta_{nm}}}
\\[5mm] & \implies
b_{m} =
{4 \over \pi}\,{\pars{-1}^{n} \over \pars{2n + 1}\on{J}_{0}\pars{\ic k_{n}R}}
\end{align}

*$\ds{\large\underline{Finally},}$
\begin{align}
&\on{u}\pars{r,z}
\\[2mm] = &\
{4 \over \pi}\sum_{n = 0}^{\infty}
{\pars{-1}^{n} \over \pars{2n + 1}
\on{J}_{0}\pars{\ic k_{n}R}}
\on{J}_{0}\pars{\ic k_{n}r}
\cos\pars{k_{n}z} 
\end{align}
A: There is more than one representation of the solution in term of series and Bessel functions. I'll try to derive the one with $\sinh$ and $\cosh$.
First, let's make the $r = R$ conditions homogenous. Let $u = 1 - v$. The new unknown $v$ satisfies the same equation
$$
\frac{1}{r}\frac{\partial}{\partial r}(r v_r) + v_{zz} = 0,
$$
but the boundary conditions are
$$
v(r=R, z) = 0\\
|v(r=0, z)| < \infty\\
v(r, z=\pm H) = 1
$$
By separation of variables $v = Q(r) Z(z)$ we have
$$
Z'' = \lambda Z\\
(rQ')' + \lambda r Q = 0.
$$
Taking $\lambda < 0$ leads us to $\sin$ and $\cos$ for $Z$ (the path you've originally taken). There's noting wrong with it, but it leads to Bessel functions with imaginary arguments.
So let's assume $\lambda = \kappa^2 > 0$.
$$
Z'' = \kappa^2 Z\\
(rQ')' + \kappa^2 r Q = 0.
$$
The solutions are $Z(z) = A \cosh \kappa z + B \sinh \kappa z$ and $Q(r) = C J_0(\kappa r) + D Y_0(\kappa r)$. And since $Y_0(x)$ is infinite at $x = 0$ we need to state that $D = 0$.
The equation $Q(R) = 0$ is
$$
J_0(\kappa R) = 0.
$$
If $\mu_n$ are the roots of $J_0(\mu) = 0$ then
$$
\kappa_n = \frac{\mu_n}{R}.
$$
The roots of Bessel functions are quite common in such problems. Moreover (see Fourier-Bessel series, A&S 11.4.5),
$$
\int_0^R J_0(\kappa_n r) J_0(\kappa_m r) r dr = \delta_{nm} R^2 \frac{J_1(\mu_n)^2}{2}.
$$
So the solution should be sought as
$$
v(r,z) = \sum_{n=1}^\infty (A_n \cosh \kappa_n z + B_n \sinh \kappa_n z) J_0(\kappa_n r).
$$
Let's put $z = \pm H$:
$$
1 = v(r,\pm H) = \sum_{n=1}^\infty (A_n \cosh \kappa_n H \pm B_n \sinh \kappa_n H) J_0(\kappa_n r).
$$
Multiplying both sides with $J_0(\kappa_m r)$ and applying $\int_0^R \bullet rdr$ on the both sides gives:
$$
\int_0^R J_0(\kappa_m r) rdr = (A_m \cosh \kappa_m H \pm B_m \sinh \kappa_m H)
R^2 \frac{J_1(\mu_m)^2}{2}.
$$
The integral on the left is $R^2 \frac{J_1(\mu_m)}{\mu_m}$ (see A&S 11.3.20), so
$$
A_m \cosh \kappa_m H \pm B_m \sinh \kappa_m H = \frac{2}{\mu_m J_1(\mu_m)}.
$$
Clearly, $B_m = 0$ (we might guess this from $z$-symmetry) and
$$
A_m = \frac{2}{\mu_m J_1(\mu_m)}\frac{1}{\cosh \kappa_m H}.
$$
Finally, the answer is
$$
u = 1 - \sum_{n=1}^\infty \frac{2}{\mu_n J_1(\mu_n)} \frac{\cosh \kappa_n z}{\cosh \kappa_n H} J_0\left(\kappa_n r\right)
$$
I made a plot with 20 terms of Felix Marin's solution (red) and mine (blue):

The $\cos$-series has oscillations near $r = R$ while $\cosh$-series has oscillations near $z = \pm H$. These oscillations are in fact, Gibb's phenomenon and are due no approximation of constant $1$ with either Fourier series $\cos k_n z$ or by Fourier-Bessel series $J(\kappa_n r)$. Far from the oscillations the solutions are almost equal up to small difference (due to truncated infinite series).
