Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How do I plot step functions in gnuplot?

  1. Jul 18, 2007 #1
    Among the demos at the gnuplot website, I saw this - http://gnuplot.sourceforge.net/demo/steps.1.gnu, but it does not make much sense to me. :(

    Could someone tell me how to plot step functions from the command line, just like you would the usual functions? Specifically, I'd like to plot floor/greatest integer functions.

    Thanks
     
  2. jcsd
  3. Jul 18, 2007 #2

    robphy

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    plot [-5:5][-5:5] floor(3*sin(x))

    plot [-5:5][-5:5] ceil(x**2)

    Your examples seem to require external data files.
     
  4. Jul 18, 2007 #3
    Thanks a lot, robphy! :-)

    EDIT: I just tried an example. While it does plot the lines of constancy, there are slanted lines that "connect" the horizontal ones. Is there a way I could get rid of them, i.e., the slanted ones?
     
    Last edited: Jul 18, 2007
  5. Jul 18, 2007 #4

    robphy

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Try to increasing the sampling resolution before plotting:

    set samples 10000
     
  6. Jul 18, 2007 #5
    Nice. Although the slants have only become vertical, they at least look like steps. :biggrin: Thanks, again. :)
     
  7. Jul 18, 2007 #6

    robphy

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    http://www6.uniovi.es/gptug/node5.html
    makes a suggestion to plot two piecewise-defined functions with illegal parts:

    f1(x)=(x<1) ? 0 : sqrt(-1)
    f2(x)=(x<1) ? sqrt(-1): 1

    plot [-5:5][-2:2] f1(x),f2(x)

    you'll have to poke around to set the color of each function to be the same
     
  8. Dec 31, 2010 #7
    You can declare a step function by using signum function by entering the command:

    u(x,t)=(1+sgn(x-t))/2
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: How do I plot step functions in gnuplot?
Loading...