Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gnuplot, check if a function exist (defined)

Tags:

gnuplot

This document demonstrates how one can check if a variable has been previously defined in a gnuplot script.

The example from the doc:

a = 10
if (exists("a")) print "a is defined"
if (!exists("b")) print "b is not defined"

However, is it possible to check if a function has been previously defined?

In other words, is there a way to do the following:

f(x) = 2*x 
if (exist("f(x)") print "Function is defined"

Thanks!

like image 779
kirbo Avatar asked Aug 29 '16 14:08

kirbo


1 Answers

Every user-defined function is available as special variable with prefix GPFUN_:

f(x) = 2*x
show variables GPFUN

prints

Variables beginning with GPFUN:
        GPFUN_f = "f(x) = 2+x"

So you can check for the function with

f(x) = 2*x 
if (exist("GPFUN_f") print "Function f is defined"
like image 189
Christoph Avatar answered Nov 15 '22 14:11

Christoph