Solution (source code)

= Solution

<Quadrupole magnets> provide transverse restoring forces proportional to displacement from the reference orbit. Their <magnetic field> increases linearly away from the axis, so an off-axis <particle> receives a kick that can bring its trajectory back toward the design orbit. A magnetic <quadrupole magnet>[quadrupole] focuses in one transverse plane and defocuses in the other; a single <quadrupole magnet>[quadrupole] cannot confine both planes.

An <alternating-gradient focusing> lattice alternates <quadrupole magnet>[quadrupole] orientations with drift spaces. With suitable strengths and separations, a focusing-defocusing sequence gives stable <betatron oscillations> in both planes. The focusing acts on transverse position, while the phase advance through the lattice converts an initial angular deviation into position and then a corrective kick. The beam is thus transported within a bounded envelope rather than allowed to drift into the pipe. Dipoles provide the main bending; the <quadrupole magnet>[quadrupole] lattice controls the small deviations.