Gnuplot interval plotting

I have an equation like this

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

How to build f (x) in one chart using gnuplot?

+3
source share
1 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 then

plot [0:40] f(x)

To clarify, the value f(x)will be:

  • xif xequal to or less than 10
  • x^2if xgreater than 10 and equal to or less than 20
  • square root of xif xgreater than 20 and equal to or less than 40
  • x^3if xmore than 40
+3
source

Source: https://habr.com/ru/post/1778063/


All Articles