Why does the Fourier series of $x$ not seem to give the right value? I'm reading a lecture about Fourier series ,
and it says that you can represent any continuous function as Fourier series.
There's a given example: 

Let $f(x) = x$. $f(x) \approx \sum_{n=1}^\infty \frac{2(-1)^{n+1}}{n}\sin(nx).$

So I can understand that $5 = f(5) = \sum_{n=1}^\infty \frac{2(-1)^{n+1}}{n}\sin(5n)$
According to wolframalpha, the sum of this series is $\approx -1.283$
What is wrong here ..?
 A: Fourier Series are used when considering periodic functions, i.e. functions which repeat after a given interval. Both sine and cosine are periodic functions; they repeat every $2\pi$.
The Fourier Series that you have given above is for the "$2\pi$-periodic extension" of function $\mathrm{f}(x)=x$. This graph is just $y=x$ when $-\pi < x < \pi$, but then it repeates over and over:

The Fourier series you give above approximates this periodic function. Below are plots of the first five and then first 20 terms of the Fourier Series:


The periodic extension does not have the property that $\mathrm{f}(5)=5$. When $x$ is bigger than $\pi$, the function repeats. We have $\mathrm{f}(x) = \mathrm{f}(x\pm 2\pi)$. The Fourier Series that you give has the property that $\mathrm{f}(5) = \mathrm{f}(5-2\pi) = 5-2\pi \approx -1.2831853$
A: For $x\neq k\pi$ , $k\in\mathbb{Z}$ , we have
$$\sum_1^\infty\bigg[2\,(-1)^{n+1}\frac{\sin nx}n\bigg]=i\ln e^{-ix}\quad\iff\quad\sum_1^\infty\bigg[2\,(-1)^{n+1}\frac{\sin 5n}n\bigg]=5-2\pi$$
The idea is that $\ \ln e^{i\alpha}=i\alpha\ $ only when $\alpha\in(-\pi,\pi]$, otherwise, it's a periodic function. Basically, you have to first subtract $\pi$ from $\alpha$ (thus determining the offset from the end of the interval), then calculate its remainder when divided through $2\pi$ (which is the length of the interval), and subtract $\pi$ yet again (since the interval starts at $-\pi$). Most falsehoods are in reality half-truths: The trouble with your formula wasn't so much that it was completely wrong, but rather that it was only local, limited to the interval $(-\pi,\pi]$.
A: This Fourier series represents the function in the interval $(-\pi,\pi)$ and converges everywhere to $f$ in that interval.
As you can already see from the formula, the Fourier series is periodic with period $2\pi$, it can therefore impossibly represent $f(x)=x$ on the entire real axis. 
Note that already for $x=\pm \pi$ it doesn't represent $f$ anymore since $\sin(\pm n \pi)=0$ for all natural numbers $n$.
As noted in the comment by ccorn, this also explains the value you got. Since $3\pi>5>\pi$ you are in the period $(\pi,3\pi)$, therefore the value of the Fourier series there should be $5-2\pi\approx-1.283$.
