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?

1

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.