What is the reason for these jiggles when truncating infinite series?

Plotting the series $$\displaystyle y = \sum_{k} \frac{\sin kx }{k}$$

In the limit it would look like

Taking a finite number of terms, I want to understand what is the reason for the jiggling at the extremes, while there the jiggling in the middle is so small its not noticable.

I truncated the sum to $1,2,3\; \mbox{and}\;4$ terms but cannot deduce much of a reason.

The "jiggling" was noticeable here because the sum is linear in the limit, however, for an expression like $$p(x) = x\prod_k\Big(1-\frac{x^2}{k^2\pi^2}\Big)$$

Does the truncated expression oscillate back and forth the limit?

-
@Qiaochu so for the second part, the answer is no? As $\sin$ is a continouous function being approximated by continuous functions, the Gibbs phenomenon should not occur. –  kuch nahi Aug 6 '11 at 19:02
I don't understand the second question. –  Qiaochu Yuan Aug 6 '11 at 19:05
In the full product, $p(x)=\sin(x)$. The partial products are not periodic, and are unbounded as $x\to\infty$. They get better for a wider range of x as more terms are incorporated into the product, but there are no discontiuities at which to observe anything like a Gibbs phenomenon. –  robjohn Aug 6 '11 at 23:02
It is gratifying to see cited a Wikipedia article whose initial version I created in November 2003---a time when the few sensible people who'd heard of Wikipedia knew that it would never be of any value. –  Michael Hardy Aug 7 '11 at 0:51

It happens that in this case, the reason becomes physically obvious if you look at it the right way. Focus on the truncated portion...the part you are throwing away. In the case of sin(kx)/k, if k is 100 or more, you effectively have a whole bunch of equal sine waves with slightly different frequencies, all in phase at a single point. It is pretty clear that this sum resonate strongly when the waves are in phase, and gradually fade to zero as they go out of phase.

If you believe that the Fourrier series adds up to what it's supposed to, then it's pretty clear that when you take away the very high frequency residue, you should expect this ringing effect around the sharp corners.

-
As Qiaochu Yuan commented, this is called the Gibbs phenomenon. It happens at discontinuities because of the behavior of the Dirichlet kernel $$D_n(x)=\sum_{k=-n}^{n}e^{ikx}=\frac{\sin((n+\frac{1}{2})x)}{\sin(\frac{x}{2})}$$ When you truncate the Fourier series of a function, $f(x)$, at the $n^{th}$ term, you get back that function convolved with the Dirichlet kernel $$D_n*f(x)=\int_{-\pi}^\pi f(y) D_n(x-y) dy$$ Here are plots of the Dirichlet kernel for $n=3$ and its integral.
Note how the integral goes from $0$ to $1$, but it wiggles because of the wavy nature of the Dirichlet kernel. This wiggle is the root of the Gibbs phenomenon. As $n\to\infty$, the kernel approaches a periodic Dirac delta distribution and its integral has a steeper slope and smaller (but tighter and more numerous) wiggles.
I should mention that since we are using $e^{ikx}$ on $\mathbb{R}/2\pi\mathbb{Z}$ instead of $e^{2\pi ikx}$ on $\mathbb{R}/\mathbb{Z}$, we need to throw in a factor of $\frac{1}{2\pi}$ when convolving with $D_n$. This factor has been incorporated in the plot of the integral. –  robjohn Aug 7 '11 at 11:15