0
$\begingroup$

How is a linear ramp StairCase Function defined with given uniform $n$ steps in domain? The Floor function forces a unit increment on the x or t independent variable, so not suitable. Thanks.

EDIT

After the below and @Kubs's comment it is seen to work, but I mistook earlier about inaccuracy from its plot, but it is ok in the Table.

xm = 2 Pi; dx = Pi/4.; Plot[Floor[x, dx]/xm, {x, 0, xm}, 
 GridLines -> Automatic]
i = 0; Table[{i++, x, Floor[x, dx]/xm}, {x, 0, xm, dx}] // TableForm
$\endgroup$
  • 5
    $\begingroup$ Can't you rescale x? $\endgroup$ – Kuba Nov 22 '16 at 14:33
  • 2
    $\begingroup$ Can you give some minimal example what the function should produce? This makes it easier for people to reason about the problem and come up with ideas for a solution. $\endgroup$ – Thies Heidecke Nov 22 '16 at 14:51
  • $\begingroup$ @Kuba Thanks, It works. Actually I thought it does not give $1$ on $y$ in the staircase plot. $\endgroup$ – Narasimham Nov 22 '16 at 15:25
  • $\begingroup$ ListStepPlot[Table[{n*Pi/4, n/8}, {n, 0, 7}], Joined -> False, GridLines -> Automatic] $\endgroup$ – Bob Hanlon Nov 22 '16 at 16:15
4
$\begingroup$

That should work:

NN = 7;
xmax = 20;
Plot[Floor[NN/xmax*x], {x, 0, xmax}]

With NN the number of steps and xmax the end of the domain.

enter image description here

$\endgroup$
  • $\begingroup$ Your solution gives out in xmax 6 instead of 1. You should normalize it! $\endgroup$ – Mirko Aveta Nov 22 '16 at 15:23
1
$\begingroup$

Is it this you are looking for?

Staircase[n_, x0_] := Sum[HeavisideTheta[x - (i/n) x0], {i, 0, n}]/n
Plot[Staircase[5, 1], {x, 0, 1}]

enter image description here

With 12 steps, it would be:

Plot[Staircase[12, 1], {x, 0, 1}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.