I've always considered gnuplot
as very useful, and even more since I use tikz
in L^{A}T_{E}X documents. Unfortunately, the number of core implemented functions in gnuplot
is quite small, I often need special functions like modified Bessel functions K_{ν} and I_{ν}. These functions cannot be written using the existing functions available in gnuplot. Is there a way to bind gnuplot and gsl
libraries ? I've been browsing gnuplotting.org and other websites dedicated to gnuplot
bu I found no word concerning this issue. If anyone has a clue, I would appreciate.
1 Answer
If you can write a command that can calculate the function you need, then you're done:
gnuplot> f(x) = real(system(sprintf("echo %f", x)))
gnuplot> plot f(x)
(see help system
)
So you can use e.g. octave to calculate your value. E.g., if your system is linux, you can have directly:
gnuplot> bJ(a,x) = real(system(sprintf("echo 'besselj(%f,%f)'  octave  grep ^ans  cut f 2 d =", a,x)))
gnuplot> plot [0:20] bJ(1,x)
It will take some time to run, though! Set the sample
value to something low until you've set every detail of your plot. If you need to replot many times, you can also tabulate your function first using set term table
and then plot the tabulated values.

Many thanks. I didn't think of
system
. For functions I used quite often, it would be worth to compile a small binary interfacing a math library like the GSL to avoid the multiple conversions in the pipe chain you suggest.– TomTomFeb 5, 2015 at 9:01 
Sure, but in that case maybe it's worth having a binary that can tabulate the function rather than return a single value. In that case, you'll end up plotting a data file with modifiers rather than an analytical function with pointwise systemrequests.– JoceFeb 5, 2015 at 14:00