evaluate user defined function in gnuplot

Viewed 307

Frequently, I end up having user-defined functions in gnuplot like the following:

a=1
b=1
y(x)=(-b+sqrt(b**2-4*a*(1-x)))/(2*a)

This allows me to easily plot y(x) and compare that with other data. But sometimes, I'd need to evaluate y(x) for a specific value (e.g. y(1)), but if I:

gnuplot> y(1)
         ^
         invalid command

My lame solution to this is to:

gnuplot> plot y(1)
Warning: empty y range [0:0], adjusting to [-1:1]

This approach gives me the right answer in the first set of square brackets. But I'm sure there's a native solution to evaluate my user-defined function in gnuplot that I couldn't find.

So: Do you know any way to evaluate user-defined functions in gnuplot?

1 Answers

You can use print. If you want to format the number you will need to print sprintf(). Eg

print y(20)
print sprintf("%5.3f",y(20))
Related