Equation for a smooth staircase function

Solution 1:

We can start with a simple soft staircase function:

$$ f(x) = x - sin \space x $$

and then feed it into itself:

$$ y(x) = f(f(x)) $$

then again:

$$ y(x) = f(f(f(x))) $$

and again:

$$ y(x) = f^4(x) $$

As you can see, each iteration makes the "flat" part of the step longer, and the rise steeper.

enter image description here enter image description here enter image description here enter image description here

The period and the height of each step is $ 2 \pi $, so multiply $x$ by $2 \pi / w$ and $y$ by $h / 2 \pi$ to reach your desired scale.

In reality, the curve is only truly flat (zero derivative) at the centre of each step — at every $ 2 \pi k $ — and only close to flat on either side of that point.

Configurability is limited: The softness of the step can only be specified in integer amounts (the number of times we reapply $f$ to itself), and it requires many/infinite applications to make the step really sharp.

Solution 2:

Here is an example based on Math536's answer: Wolfram link

$$f(h,w,a,x) = h \left[\frac{\tanh \left( \frac{ax}{w}-a\left\lfloor \frac{x}{w} \right\rfloor-\frac{a}{2}\right)}{2\tanh\left(\frac{a}{2}\right) } + \frac{1}{2} + \left\lfloor \frac{x}{w} \right\rfloor\right]$$

Where h is the step height, w is the period, and a is the smoothness