We apply the concepts of nonlinear guided-wave optics to a Bose-Einstein condensate (BEC) trapped in an external potential. As an example, we consider a parabolic double-well potential and derive coupled-mode equations for the complex amplitudes of the BEC macroscopic collective modes. Our equations describe different regimes of the condensate dynamics, including the nonlinear Josephson effect for any separation between the wells. We demonstrate macroscopic self-trapping for both repulsive and attractive interactions, and confirm our results by numerical simulations.A system of interacting bosons confined within an external potential at zero temperature can be described by a macroscopic wave function having the meaning of an order parameter and satisfying the Gross-Pitaevskii (GP) equation [1]. The GP equation is a nonlinear equation that takes into account the effects of the particle interactions through an effective mean field, and it describes the condensate dynamics in a confined geometry. Similar models of the confined dynamics of macroscopic systems appear in other fields, e.g. in the case of an electron gas confined in a quantum well, or optical modes of a photonic microcavity [2]. In all such systems, confined single-particle states are restricted to discrete energies that form a set of eigenmodes.The physical picture of eigenmodes remains valid in the nonlinear case [3], and nonlinear collective modes correspond to the ground and higher-order (excited) states of the Bose-Einstein condensate (BEC) [4]. Moreover, it is possible to observe at least the first excited (antisymmetric) collective mode experimentally [5], through the collapses and revivals in the dynamics of strongly coupled two-component BECs [6]. The interest in the nonground-state collective modes of BECs has grown dramatically with the study of vortex states, very recently successfully created in the experiment [7].The modal structure of the condensate macroscopic (ground and excited) states allows us to draw a deep analogy between BEC in a trap and guided-wave optics, where the concept of nonlinear guided modes is widely used [8]. The physical description of confined condensate dynamics in time is akin to that of stationary beam propagation along a nonlinear optical waveguide, with the BEC chemical potential playing the role of the beam propagation constant. As is well known from nonlinear optics, the guided waves become coupled in the presence of nonlinearity, and the mode coupling can lead to the nonlinear phase shifting between the modes, power exchange, and self-trapping.In this paper, we apply the concepts of nonlinear guided-wave optics to the analysis of mode coupling and intermodal population exchange in trapped BECs. As the most impressive (and also physically relevant) example of the applications of our theory, we consider the BEC dynamics in a harmonic double-well potential, recently discussed in the literature [9]. We study the coupling between the BEC ground-state mode and the first excited (antisymmetric) mode in such a poten...