Search code examples
wolfram-mathematicadiscrete-mathematicsmanipulate

How to plot a step function in Mathematica?


I want to plot a discrete function in mathematica like, for example, the following: X=[X1,x2,X3]and Y = {1 if X<=X1,20 if X1< X<=X1+X2,40 if X1+X2< X<=X1+X2+X3}

In addition I would like to use the Manipulate code to be able how the step function moves if I change the values X1,X2 or X3.

Thanks a lot for your help!


Solution

  • Manipulate[
      Plot[
        Piecewise[{{1,X<=X1},{20,X1<X<=X1+X2},{40,X1+X2<X<=X1+X2+X3}}],
        {X,0,100}],
      {{X1,25},0,100},{{X2,25},0,100},{{X3,25},0,100}]
    

    Study Manipulate Docs and Piecewise Docs until you think you have this.