This paper concerns the interaction between solitary waves on the surface of an ideal fluid and a localized external force, which models a moving disturbance on the free surface or an obstacle moving at the bottom of a channel. Previous works have investigated this interaction under the assumption that the external force moves with variable speed and constant acceleration. However, in this paper we adopt a different approach and consider the scenario in which the external force moves with variable speed and non-constant acceleration. Using the Whitham equation framework, we investigate numerically trapped waves excited by a periodic external force. Our experiments reveal regimes in which solitary waves are spontaneously generated and trapped for large times at the external force. In addition, we compare the results predicted by the Whitham equation with those of the Korteweg–de Vries equation.