Diffusion in an interval with zeroed boundaries I am attempting to solve the diffusion equation
$$\left( \partial / \partial t - D (\partial/\partial x)^2 \right) p = J$$
where $p$ is the probability density, $J$ is a source, and $D$ is the diffusion coefficient.
In particular, I'd like to solve this over the finite interval $[0, 1]$ with boundary conditions such that $(\partial p/\partial x)(x\in\{0,1\})=0$, i.e. zero space derivative at the boundaries.
Furthermore, we consider a point source
$$J(x, t) = \delta(x - x_0)\delta(t - t_0) \, .$$
As the equation is linear with constant coefficients, it seems we should solve it via Fourier transformation.
To that end, write
$$p(x, t) = \int \frac{d\omega}{2\pi} e^{i \omega t} \sum_{k=-\infty}^\infty e^{i 2\pi k x} p_k(\omega) \, .$$
Also note that
$$J(x, t) = \int \frac{d\omega}{2\pi} \sum_{k=-\infty}^\infty e^{i \omega (t - t_0)} e^{i2\pi k (x - x_0)} \, .$$
Here's where I get fuzzy.
I believe that the following are true:

*

*I do not need to do anything special to ensure that the final solution is real. The source $J$ is real and the diffusion equation is such that it will not create any imaginary content from that real source.

*I do need to do something to enforce the boundary conditions. In particular, I think it's convenient to rewrite the Fourier series in terms of $\sin$ and $\cos$.

So, let's rewrite the sum over $k$ like this:
$$
p_0(\omega) + \sum_{k=1}^\infty \left( p_k(\omega) + p_{-k}(\omega) \right) \cos(2 \pi k x) + \left(p_k(\omega) - p_{-k}(\omega) \right) \sin(2\pi k x)
\, .
$$
I think that the boundary conditions are satisfied if the $\sin$ terms vanish, which I think requires $p_k(\omega) = p_{-k}(\omega)$.
Question: Have I made a mistake yet?
Now let's stuff our Fourier representations of $p$ and $J$ into the diffusion equation.
Let $A_k(\omega) \equiv p_k(\omega) + p_{-k}(\omega)$ to clean up the notation.
\begin{align}
\left( \partial / \partial t - D (\partial / \partial x)^2 \right) \int \frac{d\omega}{2\pi} e^{i \omega t} \left[
  p_0(\omega) + \sum_{k=1}^\infty A_k(\omega) \cos(2\pi k x)
\right]
&= \underbrace{\int \frac{d \omega}{2\pi} \sum_{k=-\infty}^\infty e^{i \omega (t - t_0)} e^{i 2\pi k (x - x_0)}}_{J(x, t)} \\
\text{let $A_0 = p_0$} \quad \left( \partial / \partial t - D (\partial / \partial x)^2 \right) \int \frac{d\omega}{2\pi} \sum_{k=0}^\infty A_k(\omega) e^{i \omega t} \cos(2\pi k x)
&= \\
\int \frac{d\omega}{2\pi} \sum_{k=0}^\infty (i\omega + D(2\pi k)^2 )A_k(\omega) e^{i \omega t} \cos(2\pi k x)
&= \\
\end{align}
Now normally at this point we invoke an orthonormality statement to match coefficients term-by-term on the left and right, giving us an algebraic equation in the Fourier domain.
The problem, however, is that the sums over $k$ on the left and right run over different values.
In particular, the sum on the right (the expansion of $J$) includes the $\sin$ terms that I claimed have to be zero to satisfy the boundary conditions.
Question: What is going on here?
It seems that, maybe, a delta function source simply violates the boundary conditions, i.e. because if we write the delta function as a sequence of e.g. increasingly narrow Gaussian functions, each element in that sequence does not satisfy the boundary conditions (unless $x_0 = 1/2$).
Am I on the right track, or have I made a mistake already?
 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}$
$\ds{\bbox[5px,#ffd]{\partiald{\on{p}\pars{x,t}}{t} -
D\,\partiald[2]{\on{p}\pars{x,t}}{x} =
\delta\pars{x - x_{0}}\delta\pars{t - t_{0}},\quad D > 0,\qquad
\left.\partiald{\on{p}\pars{x,t}}{x}\right\vert_{x\ =\ 0, 1} = 0}}$

It's convenient to enforce the homogeneous boundary condition at the very begining. Namely,
$$
\partiald{\on{p}\pars{x,t}}{x} =
\sum_{n = 1}^{\infty}a_{n}\pars{t}\sin\pars{n\pi x}
$$
\begin{equation}
\mbox{which leads to}\quad\on{p}\pars{x,t} =
\sum_{n = 1}^{\infty}\on{a}_{n}\pars{t}
\bracks{-\,{\cos\pars{n\pi x} \over n\pi}} + \on{f}\pars{t}\label{pfeq}\tag{1}
\end{equation}
where $\ds{\on{f}}$ is an $\ds{x}$-independent function. $\ds{\on{p}}$ must satisfies the original equation at the top:
\begin{align}
& \bracks{-{1 \over \pi}\sum_{n = 1}^{\infty}{\dot{\on{a}}_{n}\pars{t} \over n}
\cos\pars{n\pi x} + \dot{\on{f}}\pars{t}} -
D\bracks{{1 \over \pi}\sum_{n = 1}^{\infty}\on{a}_{n}\pars{t}n
\cos\pars{n\pi x}}
\\[2mm] = &\
\delta\pars{x - x_{0}}\delta\pars{t - t_{0}}\label{eqdef}\tag{2}
\\[2mm] & \mbox{with}\quad \left\{\begin{array}{rcl}
\ds{\int_{0}^{1}\cos\pars{n\pi x}\,\dd x} & \ds{=} & \ds{0}
\\
\ds{\int_{0}^{1}\cos\pars{m\pi x}\cos\pars{n\pi x}\,\dd x} & \ds{=} & \ds{{1 \over 2}\delta_{mn}} 
\end{array}\right.
\end{align}
In integrating both sides of this expression along $\ds{\pars{0,1}}$ leads to $\ds{\dot{\on{f}}\pars{t} = \delta\pars{t - t_{0}}}$ such that $\ds{\on{f}\pars{t} = \Theta\pars{t - t_{0}} + c}$. $\ds{\Theta}$ is the Heaviside Step Function and $\ds{c}$ is a constant. The general solution (\ref{pfeq}) is reduced to
\begin{equation}
\on{p}\pars{x,t} =
-{1 \over \pi}\sum_{n = 1}^{\infty}{\on{a}_{n}\pars{t} \over n}
\cos\pars{n\pi x} + \Theta\pars{t - t_{0}} + c\label{pfeq3}\tag{3}
\end{equation}
Multiply both sides of (\ref{eqdef}) by $\ds{\cos\pars{n\pi x}}$ and integrate along $\ds{\pars{0,1}}$. It yields
\begin{align}
& -\,{1 \over 2n\pi}\,\dot{\on{a}}_{n}\pars{t} -
{D \over 2\pi}\,\on{a}_{n}\pars{t} = \cos\pars{n\pi x_{0}}\delta\pars{t - t_{0}}
\\[3mm] \implies &
\dot{\on{a}}_{n}\pars{t} +
nD\on{a}_{n}\pars{t} =
-2n\pi\cos\pars{n\pi x_{0}}\delta\pars{t - t_{0}}
\\[3mm] \implies &
\totald{\bracks{\on{a}_{n}\pars{t}\expo{nDt}}}{t} =
-2n\pi\cos\pars{n\pi x_{0}}\delta\pars{t - t_{0}}\expo{nDt}
\\[3mm] \implies &
\on{a}_{n}\pars{t}\expo{nDt} - \on{a}_{n}\pars{0} =
-2n\pi\cos\pars{n\pi x_{0}}\expo{nDt_{0}}\,\,\Theta\pars{t - t_{0}}
\\[3mm] \implies &
\on{a}_{n}\pars{t} = \on{a}_{n}\pars{0}\expo{-nDt}
-2n\pi\cos\pars{n\pi x_{0}}\expo{-nD\pars{t - t_{0}}}
\,\,\Theta\pars{t - t_{0}}
\end{align}
The solution (\ref{pfeq3}) is reduced to
\begin{align}
\on{p}\pars{x,t} & =
-\,{1 \over \pi}\sum_{n = 1}^{\infty}
\on{a}_{n}\pars{0}{\expo{-nDt} \over n}\cos\pars{n\pi x} +
\\[2mm] + & 2\Theta\pars{t - t_{0}}
\sum_{n = 1}^{\infty}\cos\pars{n\pi x_{0}}\cos\pars{n\pi x}\expo{-nD\pars{t - t_{0}}} + \Theta\pars{t - t_{0}} + c
\end{align}
$\ds{\on{a}_{n}\pars{0}}$ and $c$ are determined once a initial condition is provided $\ds{\pars{~i.e, \on{p}\pars{x,0}~}}$. In such a case, the remaining $\ds{n}$-sums can be performed analytically.
