When an external force is acting, energy is being exchanged with the system. For a mass-spring oscillator in the term system we include the losses mechanism for releasing energy to the environment. Depending on the phase shift, f, between the force and the velocity, the energy can go towards the system or out from it. (The mentioned phase shift is now, f = d-p/2.) The equilibrium state is achieved when both energies, the energy supplied to the system and the energy lost by friction are equal in the average. Then the amplitude stabilizes to the value we have stated above, giving a stored energy proportional to the square of this amplitude.
The maximum energy transfer to the system is achieved when the velocity and the external force are in phase. This corresponds to f=0 (or d=p/2), that is to say, at resonance.
The following picture was taken from the experiment:
The energies Potential, Kinetic and Total are drawn in blue, yellow and black, respectively.
To visualize just the energy of the system (mass+spring) excluding the one associated to the external Electric field, in xyZET you have to disable the computation of the Potential Energy associated to this Electric Field. This can be done by deactivating the option "variable E fields" under "pot.energy" in the "energy monitor" window.
Then you can see that a maximum rate of increase in the Total Energy happens to be when the Kinetic energy is maximum (maximum velocity) and this corresponds (at resonance) with the external force being also maximum. This is in agreement with the fact that the energy supplied to the system is force*velocity.
The resonance condition, that is to say, the situation where the frequency of the external force is equal to the natural frequency of the undamped system, is the most favorable one for transferring energy to the system. At resonance, the force and the velocity are just in phase.