The answers to the question 'How do harmonics work?' were most interesting.
OK, that's the HOW it happens. But WHY does it happen ? What is the physics here ? Why doesn't a guitar string vibrate at one frequency only?
It's a simple question with quite an involved answer.
First a quick primer on wavelength, frequency and pitch.
Frequency is how many times a vibration repeats in a period of time. Wavelength is the length of a single vibration, which for something like a guitar string, corresponds to the length of time it takes to repeat. You can see that if the wavelength halves, the frequency doubles.
Conveniently, the wavelength of the sound from a vibrating string is proportional to the length of the string, so we can talk about the two almost interchangeably.
Doubling the frequency (halving the wavelength) takes us up an octave.
When you hit/pluck/shake anything, it will vibrate at all kinds of frequency. Most of those frequencies will die away very quickly. Here's why.
These are conceptual pictures of a string vibrating. Think of one end as the nut of a guitar, and the other as the bridge. The bottom one is "not a resonant frequency", because the line doesn't end at the bridge. I could perhaps have drawn the last part of the wave with a steeper curve, so it reached the dot, and that would have shown what happens to waves of that frequency -- rather than work with the length of the string to reinforce itself, it works against the length of the string, gets cancelled out, and dies away.
Now look at the other waves. They sustain because they "fit" into the length of the string. They would carry on vibrating that way forever, if it weren't for the sound board, the friction of the air, and so forth, perhaps the magnetic field of a pickup, taking energy away.
I've shown the 1st, 2nd, 3rd and 4th -- but they keep going on, at various levels of loudness.
The complex waveform of a guitar note is the result of adding all those resonant frequencies together.
Here are some waveforms:
Here is a frequency analysis of single guitar note - horizontal axis is frequency, vertical axis is amplitude. Each spike is a different harmonic.
It's the precise mixture of frequencies, and how quickly each one dies away, that provides the timbre of the instrument.
A good way to get a feel for this is to play with an analogue synth (or a simulation of one). These use "additive synthesis", in which an oscillator produces a pure sin wave, and you build up a timbre by adding in "harmonics" using more oscillators, choosing the relative pitch and volume for each one.
You may have noticed that your guitar sounds "boomier" if you pluck it near the 12th fret, and more trebly when you pluck it near the bridge. That's because when you pluck near the middle of the string, you're giving lots of energy to the 1st harmonic, and very little to the other harmonics.
Now, what happens if you gently touch the midpoint of the string?
The result is that you subtract the fundamental note, and a lot of "odd" harmonics, leaving a harmonic that's an octave up, and some of the higher harmonics. The result is a sound with fewer harmonics that therefore sounds "purer".
A great way to get a feel for this is to play the open string, then listen carefully as you gently touch the midpoint, to see how you achieve the octave by subtracting part of the sound.
See also this other post
WHY do harmonics happen?
Well, they don't happen – not necessarily.
Strings can do all kinds of stuff:
All these are possible ways a snapshot of a moving string could look like. Not only that, it could also move at each point with an arbitrary velocity. The velocity could be everywhere 0 (for an infinitesimally short moment). This is in fact the case in the first shown state; the string would simply be in “silent mode”, i.e. no vibration. The second state is an overtone-free one (the lowest eigenstate of the string, where this is in fact the upper turnaround position).
The 4th state is a confused bunch of harmonics. By this I mean, you could take a little bit of the ground state from picture 2, something of the second harmonic (an S-like shape), a little of the 3rd and so on, add them all up and get exactly picture 4. What would that sound like? Well, just the sum of all those frequencies as overtones, like in typical string vibration as we're use to hear. Except that picture 4 is not a typical string state: I wouldn't expect to ever find a real string in that state.
In contrary to state 3: that's exactly what a guitar string looks like when you've plucked it and it's just about to slip off the nail/pick. And what happens then? Well, it moves on as if there never was a pick, i.e. as if it was in the middle of its normal movement and we simply took a snapshot which happened to look like picture 3. But picture 3 is clearly not an eigenstate: just like picture 4, the only way a string could look like this is by vibrating in multiple modes at the same time. And that's why a guitar doesn't produce sine oscillations, but proper tones with harmonics.
Actually, the opposite question is more relevant
It comes down to where the nodes, or zeros are (have a look at @MatthewRead's answer over here) as with the ends of the string fixed, any wave which has an element of movement at those points will not propagate (the end point just won't move)
So what that does is limit the possible frequencies to those which have a wavelength which fits into the string a whole number of times.
From a purely theoretical point of view it has to do with two things: Excitation and non-linearity.
As suggested by leftaroundabout's diagrams, WHERE you pluck on a string, eg, will affect to a large degree whether it vibrates primarily at the "fundamental" or some harmonic. This is excitation. So someone playing a stringed instrument can get a purer, more "fundamental" sound by plucking near the middle of the string, and a "richer", more "harmonic" sound by plucking closer to the end of the string.
Non-linearity, on the other hand, has to do with the fact that, eg, the string of a stringed instrument is not perfectly flexible, must deal with the resistance of air, and a number of other factors. This means that even if somehow initially excited to precisely the fundamental frequency, the fact that, eg, the strings are stiff at the ends will cause the ends to "lag" slightly the motion of the rest of the string, so rather than vibrating in a smooth arc the string will take on a slight S shape. If you analyze the S shape mathematically and plot its frequency spectrum, there will be a strong spike at the fundamental frequency, but (due to the S shape) weaker spikes at the overtones. In addition, the "sharp" peak at the fundamental (and the overtones) will "spread" slightly due to air resistance, etc.
It's all these subtle variations that give a musical instrument its tone. A pure fundamental tone sounds "electronic" and very artificial. (But of course, too many overtones and too much "spread" results in a muddy sound.)
I'll assume that you wonder about the harmonic components of a sound, not the guitar harmonics played by just touching the string (which was the real question behind "How do harmonics work?", I believe).
Any periodical signal can be represented as a sum of sine waves. These sine waves are shown in a spectrum: the spikes in the spectrum graph by slim represent the amplitudes of sine waves, which frequencies are given by the x-axis of the spikes.
Sum up these sine waves and you will get your original signal back. If you have only one component (one spike) in a spectrum, the signal is just a sine with that frequency and amplitude.
With that in mind, your question may be rephrased:
"Why doesn't a guitar string vibrate at one frequency only?" -> "Why doesn't a guitar string vibrate as a sine wave?"
You could say that a guitar string vibrates at one frequency (in a non-sine waveform). But its waveform may be decomposed into a sum of sine waves of different frequencies.
Now why doesn't a guitar string vibrate as a sine? As mentioned by others, this is controlled by the constraints applied to the string. The contact with the pluck, where the string is struck, the stiffness of the string, the connections to the guitar body, the body itself, the room, your fingers...
It all has to do with overtones. In a nutshell, sound is a compression wave. (It's usually drawn as a standing wave for simplicity.) Every pitch is at a set frequency, so the high point in the wave occurs every so often.
An overtone, which is what a harmonic is, happens when you have two sound waves whose high points overlap at certain intervals. For instance, an octave above any given note is twice that note's frequency, so the high points of the upper note will overlap the high points in the lower note every other time. Similar effects occur for most overtones.
A guitar string really does only vibrate at a single frequency, which is determined by its length and its tension. The overtones line up with other frequencies, which causes any appropriately tuned strings nearby to resonate with the string if they match one of the harmonics.
This is a gross oversimplification of course. This youtube video is the best explanation of the whole process I've seen in a while.
You asked "Why doesn't a guitar string vibrate at one frequency only?". Let's look at it from the other perspective: Every kind of musical instrument makes sounds that have overtones in them, and every pitch played on every kind of instrument has multiple frequencies in it--not just on the guitar. There is no repeating, oscillating sound made by any musical instrument that has absolutely no overtones. The only sound that can exist that has no overtones would be a completely pure sine wave. You could only create a pure sine wave with an electronic oscillator. No acoustic or electro-acoustic musical instrument can create a sound that is similar to a pure sine wave.
Why doesn't a guitar string vibrate at one frequency only?
An ideal one carefully plucked at its middle would, but real-world guitar strings are not idealized strings. They are not massless, they have thickness, they're often twisted bundles of metal, inconstant tension, gauge, etc. And, probably most importantly, they're plucked somewhere close to one end of the string, which is against the natural motion an ideal string would like to take. Thus, more than one mode (frequency) of the string will be vibrating; these are the harmonics.
This diagram shows what the real motion of a plucked string (black) looks like:
The colors are the different modes (overtones or harmonics) of the string's vibration. Any of these colored "strings" is a natural motion the black string would like to take. Since the red "string" has the largest amplitude, its frequency is the most prominent heard coming from the vibrating string. All these colors, when superimposed, create the non-"pure" vibration of a plucked sting. You can see the shape of the black string isn't symmetric, is "bent," unlike the colored "strings."
Plucking at the middle of the string is one way to minimize the harmonics. If you do this, you'll hear a more pure sound. This is because it's not as against the natural motion of a string as plucking near an end of the string.
So far I've seen nobody addressing the "why" question of harmonics to any useful degree: everybody is either intent on explaining how a string (as a nice example of an oscillator with overtones) can support multiple harmonics, or handwaving around the issue.
The answer is "boundary conditions". An oscillator can support multiple modes, so the question is what combination of modes will actually correspond to a certain one-time or continuous or semicontinuous excitement: the excitement places the boundary conditions. If we pluck a non-sounding string, it is formed into two straight line segments (assuming that the plucking is slow in comparison with the vibration) and then let go.
So we need to find a superposition of overtones and modes that will result in exactly the shape of the string and the forces and impulse in every part of it at the time we let go and leave it to its own devices: this will determine the various ratios of modes, and they will usually decay with different time constants, too. With strings, you can give some partials an unfair advantage by touching the string in places they would not move: then other partials die out much faster, the result being a "flageolet" or pure harmonic sound.
Also plucking a string at various points will have different overtones in the result. Some like to pluck it very close to the bridge so that it's basically the pick noise travelling back and forth the string that makes up the initial sound, rather overtone-rich until the higher partials die off.
It would vibrate only at the fundamental frequency if you excited it exactly at the middle and there were no losses in the material.
However, if you excite it randomly, it will go to an "equilibrium" status in which only standing waves multiple of fundamental frequency survive.
That is, in an ideal scenario you could generate only the desired harmonics if you excite an ideal string in the correct points.