13

I am looking for a smooth staircase equation $f(h,w,x)$ that is a function of the step height $h$, step width $w$ in the range $x$.

I cannot use the unit step or other similar functions since they are just one step. I have been experimenting with various sigmoid curves and while I can get a single smooth step I cannot get to realize the staircase shape. The closest staircase function I have found is given in this paper in equation (18) and depicted in Fig. 4 and it is a close example of what I want (i.e generate a staircase in the range $x$ for arbitrary step heights and widths) but it is not smooth at all.

Regarding smooth steps, a likely starting point I found is here but it gives a smooth function of just a single step. I have been unable to modify the equation to make it into a staircase. I would like to specify arbitrary step heights and widths and generate a smooth staircase in the range $x$ specified.

Edit (Extra info): The smooth function I mention above has the problem that the upper, horizontal line is not equal in length to the lower, horizontal line which is why I have been unable to adapt it into a staircase function

Edit 2 Including some pictures What I'm getting Desired function

Edit 2 Plot of $s$ with a steep slope showing a different width on the first horizontal line enter image description here

user1420
  • 165
  • 1
  • 1
  • 8

6 Answers6

13

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.

10

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

6

Let $s : [0,1] \to [0,1]$ be a smooth function representing a single step. Assume that there exists some $\epsilon > 0$ such that $s(x) = 0$ for all $x < \epsilon$ and $s(x) = 1$ for all $x > 1 - \epsilon$. Setting $$ f(x) = s(x - \lfloor x \rfloor) + \lfloor x \rfloor$$ then gives us a smooth staircase with steps of height and width $1$. By rescaling $f$, we can get steps of arbitrary width $w$ and height $h$: $$f(h,w,x) = h f(x/w) = h(s(x/w - \lfloor x/w \rfloor) + \lfloor x/w \rfloor).$$

Math536
  • 1,898
  • 1
    Thanks for your answer Math356 but could you also give a possible candidate for the smooth function $s$? The second function I mentioned is a little problematic in that the length of the upper, horizontal line does not match the length of the lower, horizontal line. That is, it does not resemble a smooth version of a unit step version. – user1420 Feb 25 '16 at 03:35
  • 1
    @user1420 You can find an explicit example of such a function here (look at the section "Smooth transition functions"). – Math536 Feb 25 '16 at 03:49
  • the example function you gave has the same problem. The width of the lower and upper steps vary. In the first link I posted, the function has contsant step width for all the steps. That is what I would like – user1420 Feb 25 '16 at 04:26
  • @user1420 I am not sure what you mean by "lower" and "upper" step. If you look at the graph of the function $f$ I gave in my answer, you will see that each step is composed of two parts: an horizontal line (of length, say, $L$) and an increasing "transition" part (of width $1-L$ and height $1$). Thus, I would say that all steps have the same total width, namely $L + (1-L) = 1$. Is that not what you wanted? – Math536 Feb 25 '16 at 04:34
  • Sorry for any ambiguities. Let me try plotting the entire staircase function, then I will get back to you. – user1420 Feb 25 '16 at 05:31
  • Sorry for the incessant posting. When you refer to the "horizontal line", that is what I want to be of length $w$.I think that you take the width $w$ to be the total width whereas I want the horizontal line to be of width $w$. This horizontal line is the literal "step" on a real staircase. Even when I increase the slope in your function, the horizontal line is unrelated to $w$. What I want is shown in the second figure. The first figure is an example of your function where it is seen that the horizontal line does assume the length of $w=15$. – user1420 Feb 25 '16 at 09:02
  • @user1420 Even in the second figure, the width of the horizontal line is close to $w$, but it is not exactly $w$ because of the rounded corners of the steps. If you are okay with the horizontal lines being of width $w - \epsilon$ for some small $\epsilon$, you can achieve this by taking $s$ to have a very steep slope (I can add more details in my answer to explain that). – Math536 Feb 25 '16 at 16:29
  • I you really want the horizontal lines to have width exactly equal to $w$, then I can also explain how to achieve that; however, you have to realise that in a smooth staircase, the increasing parts will always have positive width $\epsilon > 0$. If the horizontal part is of width $w$, then the $n$th step will not be between $x = nw$ and $x = (n+1)w$, as in the second figure, but rather betwwen $x = n(w+\epsilon)$ and $x = (n+1)(w + \epsilon)$. – Math536 Feb 25 '16 at 16:29
2

I used the following function, where the width of the flat part of each step is b and the width of the curved part is c, and each step is 1 unit tall:

$$ f(x) = \lfloor \frac{x}{b+c} \rfloor + \begin{cases} 0, & \text{if } x-(b+c) \lfloor \frac{x}{b+c} \rfloor, \\ s(\frac{x - (b+c) \lfloor \frac{x}{b+c} \rfloor - b}{c}) , & \text{otherwise}. \end{cases} $$

I used $\cos$ for my stepping function:

$$s(u) = \frac{1}{2} - \frac{1}{2} \cos (\large{\pi} \small{u})$$

It might look a bit simpler in Javascript code, using some temporary variables and modulus (%):

function stair (x, b, c) {
    const width = b + c;
    const base = Math.floor(x / width);    // base of this step
    const o = x % width;                   // offset, between 0 and width

    return base + (o < b ? 0 : step((o - b) / c));
}

function step (u) {
    return 0.5 - 0.5 * Math.cos(Math.PI * u);
}

although Javascript's % restricts us: x must be non-negative, and b and c must be integers .

Those restrictions can be lifted if we change how o is calculated:

    const o = x - width * base;

In Gnuplot you can experiment using:

gnuplot> f=4; c=1; plot [x=0:20] floor(x/(f+c)) + ((floor(x)%(f+c))<f ? 0 : 0.5-0.5*cos(((x - (f+c)*floor(x/(f+c))) - f) * pi/c))

enter image description here

0

You can create a smooth staircase function $f(h, w, x, t)$, which starts of as a straight line at time $t=0$, and gets progressively more pronounced steps as times passes, by solving the ordinary differential equation

$$\frac{\operatorname{d}f(h, w, x, t)}{\operatorname{d}t} = -\sin\left(2\pi \frac{f(h, w, x, t)}{h}\right)h$$

with the boundary condition

$$f(h, w, x, 0) = \frac{h\,x}{w}.$$

The solution to this ODE is

$$ f(h, w, x, t) = \begin{cases}%{ll} f(h, w, x, 0), && \text{if } \displaystyle\frac{x}{w} + 0.5 \in \mathbb{Z}\\ \displaystyle h\left(\frac{\displaystyle \tan^{-1}\left[s\,\tan\left(\frac{\pi\,x}{w}\right)\right]}{\pi} + \left\lfloor \frac{x}{w} + \frac{1}{2} \right\rfloor\right), && \text{otherwise} \end{cases}, $$

where $s=e^{-t}$, which can be interpreted as a smoothness parameter, so we can make $f$ a function of $s$ instead of a function of $t$, i.e., $f(h, w, x, s)$. $s=0$ corresponds to $t=\infty$ and means no smoothness at all (perfectly sharp steps) and $s=1$ corresponds to $t=0$ and means maximum smoothness (a straight line). Values of $s$ greater than one corresponds to negative values of $t$, and will create a basically the same type of staircase but shifted half a step. (The first case in the bracket has been added because the second case is undefined in the middle of a step since $\tan$ becomes singular at those points.)

Plots from Wolfram Alpha:

enter image description here

HelloGoodbye
  • 571
  • 2
  • 12
-1

Stair cases of Height=H and Width =W may be represented by:

$$S\left(x\right)=H\left(\frac{x}{W}+\frac{1}{2}-\frac{\arctan\left(\tan\left(\pi\left(\frac{x}{W}+\frac{1}{2}\right)\right)\right)}{\pi}\right)$$

Here you can observe https://www.desmos.com/calculator/nxmj1yqrph

926reals
  • 263