Worked example · solved on paper
A Standing Electromagnetic Wave in a Square Cavity
The problem
Consider the electromagnetic field
- (a)
Show that this field satisfies Maxwell's equations in vacuum if
\[ \omega = \frac{\sqrt{2}\, \pi c}{L}, \qquad B_0 = \frac{E_0}{\sqrt{2}\,c}. \] - (b)
The field is a standing electromagnetic wave inside a metal-walled cavity of square cross-section \(L \times L\) parallel to the \(xy\)-plane and very long in the \(z\)-direction — a cavity oscillator. Sketch \(\vec{E}\) and \(\vec{B}\). The wave number is \(k = \pi/L\), so the wavelength is \(\lambda = 2L\).
Abstract. A pair of fields is proposed for the inside of a long metal-walled pipe of square cross-section. Requiring that they satisfy Maxwell's equations in vacuum fixes both the oscillation frequency, \(\omega = \sqrt{2}\,\pi c/L\), and the ratio of the field amplitudes, \(B_0 = E_0/(\sqrt{2}c)\). Separating variables in the resulting wave equation then produces the whole family of allowed modes, \(\omega_{mn} = (\pi c/L)\sqrt{m^2+n^2}\), of which the given field is the lowest. Python turns the closed-form fields into maps of \(\vec{E}\) and \(\vec{B}\) and into an animation, which shows the electric and magnetic energy trading places twice per period. The work uses partial differentiation and the vector operators of Chapter 6 and the separation-of-variables method for partial differential equations of Chapter 10.
1The physics question
The problem hands over a pair of fields and asks whether they can exist. That is a shorter road to the same physics than solving Maxwell's equations from nothing: substituting \(\eqref{eq:Egiven}\) and \(\eqref{eq:Bgiven}\) into the four equations turns each of them into an algebraic condition, and two of those conditions are what fix the only unknowns in the problem, \(\omega\) and \(B_0\). Part (b) then names what the algebra has produced — the lowest standing-wave mode of a hollow metal pipe of square cross-section — and this report takes that one step past what was asked, separating variables in the wave equation to get the whole family of modes such a cavity supports, of which the given field is the first.
Throughout, the cross-section is centred on the origin, so \(x\) and \(y\) each run over \([-L/2,\, L/2]\). That choice matters: \(\cos(\pi x/L)\) vanishes at \(x = \pm L/2\), which is exactly the boundary condition a conducting wall imposes. Written on a \([0, L]\) grid the same formula would put a maximum on the wall and would not be a cavity field at all.
2Maxwell's equations and the boundary conditions
In a linear medium Maxwell's equations read
where \(\rho_f\) is the free charge density and \(\vec{J}_f\) the free current density, and where
with \(\vec{P}\) the polarisation (electric dipole moment per unit volume) and \(\vec{M}\) the magnetisation (magnetic dipole moment per unit volume).
2.1Boundary conditions at an interface
Let \(\mathcal{S}\) separate two homogeneous isotropic media, and let \(\hat{\mathbf{n}}\) be the unit normal pointing from medium 1 into medium 2. Applying the integral form of \(\eqref{eq:maxwell-medium}\) to a flat pillbox and to a vanishing-height loop straddling the surface gives the four matching conditions. The two integral theorems used below — the divergence theorem for the pillboxes and Stokes' theorem for the loops — are the ones proved in Chapter 6; here they do the work of turning differential equations into statements about what happens at a surface.
Gauss's law on a thin pillbox gives
and the same pillbox applied to \(\oint \vec B\cdot d\vec S = 0\) gives the magnetic counterpart. Faraday's law on a rectangular loop of length \(\Delta\ell\) whose height goes to zero encloses no flux, so
and the Ampère–Maxwell law on that loop encloses only the surface current. Together, \(\eqref{eq:pillbox}\) and \(\eqref{eq:loop}\) give the four matching conditions
Inside a perfect conductor both fields vanish, so the second and third of \(\eqref{eq:bcs}\) say that at the cavity wall the tangential electric field and the normal magnetic field must be zero. For the field \(\eqref{eq:Egiven}\) the only component of \(\vec E\) is tangential to every wall, which is why \(E_z\) has to vanish on all four of them.
2.2Reduction to the source-free vacuum equations
Inside the cavity there are no free charges or currents and no matter to polarise: \(\rho_f = 0\), \(\vec{J}_f = 0\), \(\vec{P} = \vec{M} = 0\). Equations \(\eqref{eq:maxwell-medium}\) collapse to
with \(c = 1/\sqrt{\varepsilon_0 \mu_0}\).
3(a) Verifying the field
Each of the four equations in \(\eqref{eq:maxwell-vacuum}\) is now checked in turn. Every step is a partial derivative of a product of sines and cosines — the machinery of Chapter 6.
3.1Divergence of \(\vec{E}\)
With \(\nabla = \hat{\mathbf{i}}\,\frac{\partial}{\partial x} + \hat{\mathbf{j}}\,\frac{\partial}{\partial y} + \hat{\mathbf{k}}\,\frac{\partial}{\partial z}\) and \(\vec{E} = E_z\hat{\mathbf{k}}\),
because \(E_z\) does not depend on \(z\).
3.2Divergence of \(\vec{B}\)
Here \(B_z = 0\) and
which cancel term by term, so
3.3Curl of \(\vec{E}\): Faraday's law
Since \(\vec E\) has only a \(z\)-component,
and with
equation \(\eqref{eq:curlE-general}\) becomes
Differentiating \(\eqref{eq:Bgiven}\) in time,
Equations \(\eqref{eq:curlE}\) and \(\eqref{eq:dBdt}\) agree, with the same spatial pattern and the same time dependence, provided
3.4Curl of \(\vec{B}\): the Ampère–Maxwell law
Only the \(z\)-component survives:
so that \(\eqref{eq:curlB-general}\) gives
while the displacement-current term is
Matching the coefficients of \(\eqref{eq:curlB}\) and \(\eqref{eq:displacement}\),
3.5Solving the two matching conditions
Equation \(\eqref{eq:match1}\) gives \(B_0 = \pi E_0/(L\omega)\). Substituting into \(\eqref{eq:match2}\),
so that
as required. Note what the two conditions did: Faraday's law fixed the ratio of the amplitudes, and the Ampère–Maxwell law then fixed the frequency. Neither equation alone determines both.
4(b) What the field looks like
The field is a standing wave. Both \(\vec{E}\) and \(\vec{B}\) keep a fixed spatial shape and simply breathe in amplitude, and because one carries \(\sin\omega t\) while the other carries \(\cos\omega t\), they are a quarter period out of step: whenever \(\vec{E}\) is at its largest, \(\vec{B}\) is momentarily zero, and conversely.
Because \(B_z = 0\) while \(E_z \ne 0\), this is a transverse magnetic (TM) mode with respect to the long axis of the cavity, the lowest member of that family. Figure 1 shows the two fields, each at the instant it is largest.

Figure 2 runs one full period of the oscillation. Plotting \(E_z\) as a height turns the standing wave into a surface that swells, flattens and inverts without its shape ever changing; the upright arrows are the electric field vector itself, and \(\vec{B}\) — which lies in the plane — is drawn as arrows on the floor beneath. The quarter-period phase shift then needs no explaining: the surface is flat, and the upright arrows are gone, exactly when the floor arrows are longest.

5The full family of modes
Nothing above required the particular pattern in \(\eqref{eq:Egiven}\). Solving the cavity from scratch produces every mode it supports, and the given field turns out to be the lowest one.
5.1Wave equation
Take the curl of Faraday's law and use \(\nabla \times (\nabla \times \vec{E}) = \nabla(\nabla \cdot \vec{E}) - \nabla^2\vec{E}\) together with \(\nabla\cdot\vec{E} = 0\):
Every Cartesian component of both fields satisfies the same scalar wave equation — the partial differential equation of Chapter 10.
5.2Separation of variables (Chapter 10)
This is the method of Chapter 10 applied unchanged. Look for a solution of \(\eqref{eq:wave}\) with no \(z\)-dependence in the product form \(E_z(x,y,t) = X(x)\,Y(y)\,T(t)\). Substituting and dividing by \(XYT\) gives
in which the first term depends only on \(x\), the second only on \(y\) and the third only on \(t\). Three functions of independent variables can agree only if each is a constant, so \(\eqref{eq:separated}\) splits into
The signs in \(\eqref{eq:three-odes}\) are forced: a positive separation constant would give growing exponentials, which cannot vanish on both walls.
5.3Applying the walls
\(E_z\) is tangential to all four walls, so it must vanish at \(x = \pm L/2\) and at \(y = \pm L/2\). Measuring from the wall at \(x = -L/2\), the admissible solutions are
with
For \(m = n = 1\) the shifted sine is just \(\cos(\pi x/L)\), so \(\eqref{eq:modes}\) reproduces the field of the problem and \(\eqref{eq:omega-mn}\) reproduces \(\omega_{11} = \sqrt{2}\pi c/L\), confirming \(\eqref{eq:answer-a}\). Writing the modes as shifted sines rather than as \(\cos(m\pi x/L)\) matters for the higher ones: the plain cosine satisfies the boundary condition only when \(m\) is odd, and would put an antinode on the conductor when \(m\) is even.
The six lowest modes are shown in Figure 3. Their frequencies are not multiples of one another — \(\sqrt{m^2+n^2}\) is rarely a rational multiple of \(\sqrt2\) — and modes related by swapping \(m\) and \(n\) are degenerate, sharing one frequency between two distinct field patterns.

Once \(E_z\) is known, \(\vec{B}\) follows from Faraday's law, so \(\eqref{eq:modes}\) determines the mode completely.
6Energy in the cavity
The energy density of the field is \(u = \tfrac{1}{2}\varepsilon_0 E^2 + B^2/(2\mu_0)\). Integrating it over the cross-section is a double integral of the kind set up in Chapter 5, and the only fact needed is \(\int_{-L/2}^{L/2}\cos^2(\pi x/L)\,dx = L/2\). Using \(\eqref{eq:Egiven}\) and \(\eqref{eq:Bgiven}\) with \(B_0 = E_0/(\sqrt{2}c)\) from \(\eqref{eq:answer-a}\),
so the total \(U_E + U_B\) is constant, as it must be for a lossless cavity. The two peak values come out equal — a check the script prints when it runs, and the content of Figure 4. The energy sloshes back and forth between the electric and magnetic field twice per period, exactly as it does between the capacitor and the inductor of an \(LC\) circuit.

7Which course methods were used
Partial differentiation and vector operators (Chapter 6). Verifying the field is four exercises in taking divergences and curls of products of sines and cosines; the two matching conditions \(\eqref{eq:match1}\)–\(\eqref{eq:match2}\) fall straight out of them.
Partial differential equations (Chapter 10). Eliminating \(\vec{B}\) turns Maxwell's equations into the wave equation, and separation of variables plus the wall conditions turns that into the discrete family \(\eqref{eq:modes}\). The quantisation of \(\omega_{mn}\) is a boundary-value problem, not a property of the wave equation itself.
Fourier series (Chapter 7). The modes \(\eqref{eq:modes}\) are a complete orthogonal set on the square, so any field the cavity can hold is a double Fourier sine series in these patterns — which is what lets us treat the lowest mode on its own.
Multiple integrals (Chapter 5). The stored energies \(U_E\) and \(U_B\) are area integrals of the energy density over the cross-section.
8Conclusion
Requiring the proposed field to satisfy Maxwell's equations in vacuum forces \(\omega = \sqrt{2}\pi c/L\) and \(B_0 = E_0/(\sqrt{2}c)\), and the field is then the lowest TM mode of a square cavity. Solving the same problem by separation of variables gives the whole spectrum \(\omega_{mn} = (\pi c/L)\sqrt{m^2+n^2}\), with degenerate pairs whenever \(m \neq n\). The visualisation shows what the algebra states: a field frozen in shape, oscillating in amplitude, passing its energy back and forth between \(\vec{E}\) and \(\vec{B}\) twice each period, and going to zero at the conducting walls.
References
M. L. Boas, Mathematical Methods in the Physical Sciences, Wiley, 3rd ed., 2006 (Problem 11.13, Chapter 6).
D. J. Griffiths, Introduction to Electrodynamics, Cambridge University Press, 5th ed., 2023 (waveguides and cavities).