New definition for triangle wave?

1k Views Asked by At

There's always a huge formula for the triangle wave, or the "teeth" function as I like to call it. Shouldn't this give a teeth function too? It's sorta hard to understand, but once you get the hang of it, it works out fine. This one produces $(-2,2), (0,0), (2,2), (4,0)$, etc.

$f(x) = |x-4k|$, where $4k-2 \leq x \leq 4k+2$ and $k$ is an integer. Plug in different $k$ values $(0, 1, 2, etc)$

1

There are 1 best solutions below

0
On

You are right: this formula defines a triangular wave. It's certainly nothing new, though.

An even shorter formula for the same function can be given using the concept of distance from a point to a set: $$f(x)=\operatorname{dist}(x,4\mathbb Z)$$

But the above is not likely to be understood by a computer, if you want to use it for graphing. In that case, I would go for something like $$f(x)= \Big|x-4 \lfloor x/4+1/2\rfloor\Big|$$ Tested in WA