4

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?

pr4n
  • 2,918
  • 3
  • 30
  • 42

1 Answers1

3
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
darioo
  • 46,442
  • 10
  • 75
  • 103
  • 1
    What I did was to write a Python code that generates the values of X and Y and then plot using filename. This approach works great for two intervals. What if there are more than two? – pr4n Dec 04 '10 at 05:06