Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I use gnuplot for plotting functions. This is my script at the moment:

set terminal png xffffff x222222
set output "Ausgleichszahlungen.png"
set title "Ausgleichszahlungen"
set xlabel 'F_MZ / A_MZ'
set ylabel 'Faktor F'
set xrange [0.5:1]
set yrange [0:1]
set key off
set xzeroaxis linetype -1 linewidth 0.5
set yzeroaxis linetype -1 linewidth 0.5
set xtics 0.1
set ytics 0.1
f(x) =                        0.75   * (1-x) -  317.0 /  20000
g(x) = 5.0/26 * (1-x) ** 2 + 35.0/52 * (1-x) - 2121.0 / 260000.0
h(x) = 13.0/7 * (1-x) ** 2 + 11.0/25 * (1-x)
plot f(x), g(x), h(x)

f(x), g(x) and h(x) are one function:

-infinity < x < 0.8 : f(x)

0.8 <= x < 0.93 : g(x)

0.93 <= x < +infinity: h(x)

How can I do this?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Change the last line to

plot f(x)*(x<0.8) +  g(x) * (x>=0.8)*(x<0.93) + h(x)*(x>=0.93)

I find that easy to read, but it has the disadvantage that all f(x), g(x) and h(x) will always be evaluated. You can also use the ternary conditional operator:

condition ? case1 : case2

will evaluate to case1 if condition is true and to case2 if condition is false. You can nest those, so

plot x < 0.8 ? f(x) : x < 0.93 ? g(x) : h(x)

will do the job for you.

share|improve this answer
    
Hi Jan, it works fine, thanks. gnuplot.info/docs_4.2/gnuplot.html is quite interesting if someone else is searching for basic problems in gnuplot. –  moose Jan 26 '11 at 20:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.