To create a truly localized wavepacket we need to superpose not just two but an infinite amount of sinusoidal waves whose wavelengths and amplitudes vary in a continuous spectrum. To do that, we need to learn about what’s called the Fourier integral:
Why an exponential function instead of sine and cosine? This is because we just used Euler’s formula:
and it’s derivations:
to replace the sines and cosines with the exponential function.
Essentially, this gives us a framework for expressing practically any function as a superposition of harmonic waves (just plug in the function in the expression for and then plug in into the expression for the Fourier integral). This is known as the Fourier transform.