We develop a theory for the energy loss of swift electrons traveling parallel to an ordered array of polarizable spheres. The energy loss is given in terms of a surface response function which is expressed as a spectral representation. The poles and weights in this representation are determined through the eigenvalues and eigenvectors of an interaction matrix. This matrix takes account of the quasistatic electromagnetic interaction between the polarized spheres to an arbitrary multipolar order. We use our theory to calculate the energy-loss spectra for cubic arrays of aluminum spheres with various numbers of layers and compare the results with those obtained using a dielectric continuum model. @S0163-1829~99!05843-9# Electron-energy-loss spectroscopy ~EELS! of inhomogeneous systems has been an active field of research during the last decades. Here, we will be interested in the calculation and analysis of EELS spectra of granular matter. The calculation of the energy loss of swift electrons passing through a system of nanometric inclusions embedded in an otherwise homogeneous matrix was stimulated by the recent experiments of Walsh. 1 The concept of an effective medium for the calculation of the energy-loss function in a granular composite has been very appealing because one might expect that this function could be written in terms of the effective dielectric function associated with the composite. The first attempts along these lines were done by using the effective dielectric functions which had proved to be successful in describing the optical properties of granular composites, 1 like the ones devised, for example, by Maxwell Garnett, 2 Bruggeman, 3 or Landau and Lifshitz. 4 The main problem encountered in using these types of effective dielectric functions was that the peaks in energy loss coming from the excitation of the bulk plasmons of the inclusions did not appear in the calculated spectra. The origin of this problem was the local nature of the effective dielectric response, that is, the effective dielectric response depended only on the frequency of the applied field and had no dependence on its wave vector. This actually means that the response is valid only in the limit as the wave vector tends to zero. Although this limit might be appropriate when the system interacts with light, this is certainly not true when the applied field is the field carried by a moving electron, as in the case of EELS. One would expect that an effective dielectric function that could describe properly the energy-loss process should be nonlocal, that is, should depend on the frequency and the wave vector of the applied field. This approach was taken by Barrera and Fuchs, 5 who find a nonlocal effective dielectric response that could be used to calculate the energy-loss spectra of fast electrons passing through a system of random spherical inclusions contained in a matrix. In their approach, it was assumed that both the spheres and the matrix were described by local dielectric responses but the interaction among the polarized spheres was taken to all multipolar orders within the mean-field approximation. The calculated spectra using this theory showed well-defined peaks coming from the excitation of the bulk plasmons of the inclusions and the matrix, as well as the ones coming from the excitation of interfacial modes, that is, modes in which the induced charge is located at the interface of the spheres and the matrix. These calculated spectra also agreed with the experimental spectra of Walsh. Further theoretical developments 6 also showed the merits and limitations of an ad hoc phenomenological theory 7 devised to explain the experimental results. These developments have also shown the possibility of defining an effective local dielectric response that could describe the energy-loss process. There is also interest in the calculation of energy-loss spectra for an experimental setup in which the electron trav