Interval graph plotting in gnuplot

gnuplotgraph

I have an equation which goes like this

f(x) = x*10 ; 0 < x <= 10
     = x*x + x*10 ; 10 < x < 20

How do I plot f(x) in one graph using gnuplot?

Best Answer

plot [0:20] x <= 10 ? x*10 : x*x + x*10

Update: if you have more than two functions, you can use this approach:

f(x) = x <= 10 ? x \
     : x <= 20 ? x**2 \
     : x <= 40 ? sqrt(x) \
     : x**3

and afterwards,

plot [0:40] f(x)

To clarify, value f(x) will be:

  • x if x is equal or less than 10
  • x^2 if x is greater than 10 and equal or less than 20
  • square root of x if x is greater than 20 and equal or less than 40
  • x^3 if x is greater than 40