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

1 Answer
Aug 22, 2015

It's possible to impersonate it with...

#((abs(sin(x*pi/2))-abs(cos(x*pi/2)))*(tan(x*pi/2)/abs(tan(x*pi/2)))+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...

#3/5(abs(sin(x*pi/2))-abs(cos(x*pi/2))-1/6abs(sin(x*pi/2)^3)+1/6abs(cos(x*pi/2)^3))*tan(x*pi/2)/abs(tan(x*pi/2))+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]}