Modeling physical systems by effective harmonic oscillators: The optimized quadratic approximation