A curious graph of f(1/n) from the Spivak's Calculus I am self-studying through Spivak's Calculus and on the fourth chapter, I got stuck at the plot of a function. It's on the page 61 by the way. The function is this and piecewisely defined;
 
$$f(1/n) = (-1)^{(n+1)}$$
$$f(-1/n) = (-1)^{(n+1)}$$ and
$f(x) = 1$ when $\mid{x}\mid\geq1$ 
So the interesting part is part of the graph between -1 and 1. Spivak says the function oscillates at each interval such as [1/n+1, 1/n] and each such interval behaves as a linear line segment. So when n = 3, we have f(1/3) = 1 and when n=2 we have f(1/2) = -1 and f behaves like a line in the interval [1/3, 1/2], going from -1 to 1. Spivak says we can even find a line equation for each such interval [1/n+1, 1/n]. But I can't see how this graph is made of straight lines. Can anyone explain this to me?
 A: Take a look at the book again, he said two things: "The graph in figure 18 is made up entirely of straight lines" and "The function $f$ with this graph satisfies [formulas] and is a linear function on each interval [intervals]." 
He says that the function in figure $18$ satisfies those formulas, not that these formulas are the function pictured in figure $18$. With the formulas in that page, you can only do - assuming a function $\Bbb{N}\to \Bbb{R}$. If you take $\Bbb{R}\to\Bbb{R}$ or $\Bbb{Q}\to\Bbb{R}$  - some values will have their images in $\Bbb{C}$.



The function in the next page is as follows. 



And then he says that we can build explicit formulas for the intervals of those points, that is: We can fill the spaces just as the previous graph and extend the domain to $\Bbb{R}$. A very important idea is to be able to manipulate/construct functions with operations like gluing/distorting/etc any other kinds of known functions. As an example: One remarkable idea is that you can approximate functions such as $\sin(x)$ by polynomials. 
Another really interesting example is the gamma function. If you take $f(n)=n!$, this is only defined for $n \in \Bbb{N}$. What if you want to fill the spaces between the points? One answer is the gamma function, another possible answer is the Stirling approximation for factorials:



A: The author is constructing a piecewise function from a set of points; so what he did was to plot $y$-values of $1$ at the points $x=1,\frac{1}{3},\frac{1}{5} ... $, and $-1$ at $x = \frac{1}{2},\frac{1}{4},\frac{1}{6}...$.
He then joins these points together, and the lines that join them together are linear functions defined differently on each interval $[1/(n+1), 1/n]$, i.e. 'piecewise'.
The exact expression of each piecewise function is not given, but it's easy to find. If I'm not mistaken, the entire point of the illustration is to introduce the concept of piecewise-defined functions.
(For completeness, the formula in the case of $x>0$ should be $f(x) =-1+2\frac{\left(x-\frac{1}{n+1}\right)}{\left(\frac{1}{n}-\frac{1}{n+1}\right)}=-1+2n(n+1)\left(x-\frac{1}{n+1}\right)$ in $[1/(n+1), 1/n]$ when $n$ is odd, and something similar when n is even.)
A: $$f(x)=\cases{4n(2n-1)x-4n+1 & \text{if}\quad \dfrac{1}{2n}< x\leqslant\dfrac{1}{2n-1},\cr 4n+1-4n(2n+1)x& \text{if} \quad\dfrac{1}{2n+1}<x\leqslant\dfrac{1}{2n},}$$for each nonzero integer $n$, with $f(x)=1$ otherwise.
