# How can we graph the sawtooth function x - floor(x)?

Aug 22, 2015

It's possible to impersonate it with...

$\frac{\left(\left\mid \sin \left(x \cdot \frac{\pi}{2}\right) \right\mid - \left\mid \cos \left(x \cdot \frac{\pi}{2}\right) \right\mid\right) \cdot \left(\tan \frac{x \cdot \frac{\pi}{2}}{\left\mid \tan \left(x \cdot \frac{\pi}{2}\right) \right\mid}\right) + 1}{2}$

...or better if you add some cubed terms.

#### Explanation:

Without the hashes, that's:

((abs(sin(x * pi/2))-abs(cos(x * pi/2))) * (tan(x * pi/2)/abs(tan(x * pi/2)))+1)/2

Here's how it looks...

graph{((abs(sin(xpi/2))-abs(cos(xpi/2)))(tan(xpi/2)/abs(tan(x*pi/2)))+1)/2 [-4.98, 5.02, -2, 3]}

Not entirely convincing, but probably close enough.

For better linearity, add some cubed terms...

$\frac{3}{5} \left(\left\mid \sin \left(x \cdot \frac{\pi}{2}\right) \right\mid - \left\mid \cos \left(x \cdot \frac{\pi}{2}\right) \right\mid - \frac{1}{6} \left\mid \sin {\left(x \cdot \frac{\pi}{2}\right)}^{3} \right\mid + \frac{1}{6} \left\mid \cos {\left(x \cdot \frac{\pi}{2}\right)}^{3} \right\mid\right) \cdot \tan \frac{x \cdot \frac{\pi}{2}}{\left\mid \tan \left(x \cdot \frac{\pi}{2}\right) \right\mid} + \frac{1}{2}$

3/5(abs(sin(x * pi/2))-abs(cos(x * pi/2))-abs(sin(x * pi/2)^3)/6+abs(cos(x * pi/2)^3)/6) * tan(x * pi/2)/abs(tan(x * pi/2))+1/2

graph{3/5(abs(sin(xpi/2))-abs(cos(xpi/2))-abs(sin(xpi/2)^3)/6+abs(cos(xpi/2)^3)/6)tan(xpi/2)/abs(tan(x*pi/2))+1/2 [-2.48, 2.52, -0.75, 1.75]}