I'm trying to determine the maximum final velocity of a body with which it contracts a spring until it touches the wall. It happens only with the presence of maximum energy. So, I've taken the kinetic energy and used the first derivative to obtain the maximum velocity. Is this the right way to solve this problem? It only gives the minimum velocity which is zero..!
use the principle of conservation of energy. the total work done on the spring will equal the total change in kinetic energy(final kinetic energy minus initial kinetic energy. the work for a from a spring can be calculated by integrating hook's law from the initial to the final position. more intuitively you can think that in the spring-object system the potential force from the spring will balance out the kinetic energy, hence the kinetic energy will be at its maximum when the potential energy is zero, that is at the equilibrium position of the spring.