Expansion of the derivatives of the electric and magnetic fields I'm reading electrodynamics physics notes that describe a cavity of length $L$. The cavity is said to lie along the $z$-axis from $-L$ to $0$. The electric field is polarized in the $x$ direction and the magnetic field is polarized in the $y$ direction.
It then says that the basis functions for expansion of the electric and magnetic fields are
$$u_n(z) = \sin(k_n z) \ \ \ \ \ \ \text{and} \ \ \ \ \ \ v_n(z) = \cos(k_n z),$$
with
$$k_n = n \pi/L$$
These satisfy the relationship
$$\dfrac{\partial{u_n}(z)}{\partial{z}} = k_n v_n(z), \\ \dfrac{\partial{v_n}(z)}{\partial{z}} = -k_n u_n(z),$$
but are said to be "unnormalized" (I'm not totally sure what this means in this case).
It then says that fields in the cavity are expanded as
$$E(z, t) = \sum_n A_n(t) u_n(z), \\ H(z, t) = \sum_n H_n(t) v_n(z),$$
while the expansion of their derivatives follows from the above definitions to become
$$\begin{align*} \dfrac{\partial{E(z, t)}}{\partial{z}} &= \dfrac{2}{L} \sum_n v_n(z) \left( \int_{-L}^0 dz \ v_n(z) \dfrac{\partial{E(z, t)}}{\partial{z}} \right) \\ &= \sum_n v_n(z) \left( \dfrac{2}{L} E(0, t) + k_n A_n(t) \right), \end{align*}$$
$$\begin{align*} -\dfrac{\partial{H(z, t)}}{\partial{z}} &= \dfrac{-2}{L} \sum_n u_n(z) \left( \int_{-L}^0 dz \ u_n(z) \dfrac{\partial{H(z, t)}}{\partial{z}} \right) \\ &= \sum_n u_n(z) k_n H_n(t) \end{align*}$$
I understand that these last equations are derived using Fourier series (along with using integration by parts), but I have been unable to replicate this derivation, and, so far, no one has been able to explain to me how this is done. It seems to me that it may be the case that mathematical knowledge of Fourier series alone is not enough to understand how to derive these equations; or, perhaps, the author made some error in their derivation. With that said, I presume that physicists understand what's going on here (given the context) and how Fourier series is used to derive these equations, and so are more qualified to help me with this. So that leads me to my question: How are these last equations derived? I have been wrestling with this for weeks now, and I just cannot seem to figure it out, so I'd greatly appreciate it if someone would take the time to show me.
 A: I don't fully understand the physics here, but I've tried to give a mathematical explanation.
Firstly I'll just quote some standard Fourier transform results. The cosine Fourier series is
$$f(x)=\frac{a_0}{2}+\sum_{n=1}^{\infty}a_n\cos\left(\frac{n\pi x}{L}\right) \quad \text{where}\quad a_n=\frac{2}{L}\int_0^L\mathrm{d}x\,\cos\left(\frac{n\pi x}{L}\right)f(x)$$
and the sine Fourier series is similarly
$$f(x)=\sum_{n=1}^{\infty}b_n\sin\left(\frac{n\pi x}{L}\right) \quad \text{where}\quad b_n=\frac{2}{L}\int_0^L\mathrm{d}x\,\sin\left(\frac{n\pi x}{L}\right)f(x).$$
Your situation is slightly different as the region is from $-L$ to $0$ but all this does is change the integration limits (which can be seen by considering $x\rightarrow -x$). Note that you can use either the sine or cosine Fourier series as we are only interested in this region.
Your notes expand $E(z,t)$ as a sine Fourier series and $H(z,t)$ as a cosine Fourier series so, assuming $H(z,t)$ has no constant $a_0$ component,
$$E(z, t) = \sum_n A_n(t) u_n(z), \\ H(z, t) = \sum_n H_n(t) v_n(z)$$
where $u_n(z)=\sin(k_n z)$ and $v_n(z)=\cos(k_n z)$ for $k_n=n\pi/L$ and, using the standard results,
$$A_n(t)=\frac{2}{L}\int_{-L}^0\mathrm{d}z\,u_n(z) E(z,t), \\ H_n(t)=\frac{2}{L}\int_{-L}^0\mathrm{d}z\,v_n(z) H(z,t). $$
There is a subtlety in that the Fourier series is only convergent with respect to the norm which means it does not necessarily converge at every point $z$. For example, in your problem $E(0,t)$ seems to be non-zero (yet apparently $E(-L,t)$ is zero), but in the Fourier expansion we find $E(0,t)=0$, so the Fourier series does not converge at $z=0$. This causes a problem for $\partial E(z,t)/\partial z$ as the Fourier series is not differentiable at $z=0$. We can fix it in an extremely dodgy physics way by adding a Kronecker delta to the expansion like
$$E(z, t) = \sum_n A_n(t) u_n(z) + E(0,t)\delta_{z,0}$$
which has derivative
$$\frac{\partial E(z, t)}{\partial z} = \sum_n A_n(t) \frac{\partial u_n(z)}{\partial z} + E(0,t) \frac{\partial \delta_{z,0}}{\partial z}$$
The first term is evaluated easily to be
$$\sum_n A_n(t) \frac{\partial u_n(z)}{\partial z} = \sum_n k_n A_n(t) v_n(z)$$
and the second term can be expressed formally as a cosine Fourier series with coefficients
$$a_n=\frac{2}{L}\int_{-L}^0\mathrm{d}z\,v_n(z) E(0,t) \frac{\partial \delta_{z,0}}{\partial z}\\=\left[\frac{2}{L}v_n(z)E(0,t)\delta_{z,0}\right]_{-L}^0-\frac{2}{L}\int_{-L}^0\mathrm{d}z\,\frac{\partial v_n(z)}{\partial z} E(0,t) \delta_{z,0}=\frac{2}{L}E(0,t)$$
using integration by parts. The integral is zero because the integrand is zero except for at $z=0$ where it is only finite. Thus we have
$$E(0,t) \frac{\partial \delta_{z,0}}{\partial z}=\sum_n v_n(z) \frac{2}{L} E(0,t)$$
and so we find
$$\frac{\partial E(z, t)}{\partial z} = \sum_n v_n(z) \left(\frac{2}{L} E(0,t)+ k_n A_n(t) \right)$$
which is the first of your expressions.
$H(z,t)$ on the other hand does not have this problem as the cosine series is not automatically zero at the boundary and differentiating gives
$$-\frac{\partial H(z, t)}{\partial z} = -\sum_n H_n(t) \frac{\partial v_n(z)}{\partial z} = \sum_n k_n H_n(t) u_n(z)$$
which is the second result.
The somewhat easier way to derive this, which is probably what your notes did, is by expressing the derivatives as Fourier series directly. They expand $\partial E(z,t)/\partial z$ in a cosine series as
$$ \frac{\partial{E(z, t)}}{\partial{z}} = \frac{2}{L} \sum_n v_n(z) \left( \int_{-L}^0 dz' \ v_n(z') \frac{\partial{E(z', t)}}{\partial{z'}} \right)$$
which, as with $E(z,t)$ itself, just comes from the standard results. The integral can be done by parts to give
$$\frac{2}{L}\int_{-L}^0 dz \ v_n(z) \frac{\partial{E(z, t)}}{\partial{z}} = \left[\frac{2}{L} v_n(z) E(z,t) \right]_{-L}^0-\frac{2}{L}\int_{-L}^0 dz \ \frac{\partial{v_n(z)}}{\partial{z}} E(z, t) \\ = \frac{2}{L}E(0,t)+ k_n\frac{2}{L}\int_{-L}^0 dz \ u_n(z) E(z, t).$$
However, note that the second term is just $k_n$ times $A_n(t)$ and so
$$\frac{2}{L}\int_{-L}^0 dz \ v_n(z) \frac{\partial{E(z, t)}}{\partial{z}} =  \frac{2}{L}E(0,t)+ k_n A_n(t)$$
which gives
$$\frac{\partial E(z, t)}{\partial z} = \sum_n v_n(z) \left(\frac{2}{L} E(0,t)+ k_n A_n(t) \right).$$
Similarly, for $\partial H(z,t)/\partial z$, they expand it as a sine series
$$ -\frac{\partial{H(z, t)}}{\partial{z}} = -\frac{2}{L} \sum_n u_n(z) \left( \int_{-L}^0 dz' \ u_n(z') \frac{\partial{H(z', t)}}{\partial{z'}} \right),$$
the integration by parts gives
$$\frac{2}{L}\int_{-L}^0 dz \ u_n(z) \frac{\partial{H(z, t)}}{\partial{z}} = \left[\frac{2}{L} u_n(z) H(z,t) \right]_{-L}^0-\frac{2}{L}\int_{-L}^0 dz \ \frac{\partial{u_n(z)}}{\partial{z}} H(z, t)= -k_n H_n(t)$$
and we finally have
$$-\frac{\partial H(z, t)}{\partial z} = \sum_n k_n H_n(t) u_n(z).$$
Some of this is quite dodgy and I'm not really sure what they are trying to do, but I hope it explains where the equations come from.
