Gnuplot calculator

A few weeks back I wrote a post on calculators, expressing my desire for something that was more than a push-button emulator, and less than a full programming language. Something where you just have a window  where you can type 2.3*Msun*c**2, define short expressions for re-use, etc. Python seems to be the obvious thing but it has some annoying quirks; I also recommended Plaincalc. The comment stream was fascinating and very educational, with pointers to Wolfram Alpha, the Statusbar calculator for Firefox, and iCosmo, as well as some Python tutorial from Ross C.

I have been thinking about a similar post on graph plotters. While playing with these, I suddenly realised that the plotting package I use most often, gnuplot, does exactly whats needed ! Doh ! You can do calculations – eg print 18.3 * 27.6. You can define and use variables – eg a=pi/6, b=18.3, and then c=b**2*sin(1.3*a).  You can define and use single expression functions – e.g. f1(a,b,x)=a*x**2+b*sin(x)/x;  then with a and b already set you can calculate g=f1(a,b,2.3)/f1(a,b,3.2). Finally of course you can plot f1(a,b,x) – gnuplot assumes x is the variable and other variables are parameters. Then you can change the values of a and b and replot.

So now I have a file of physics and astro constants which is loaded by my .gnuplot initialisation file, so I can type 2.3*Msun*c**2. Next up, some standard functions, eg RBB(nu,T) = (2.*pi/c**2) * nu**3  / (exp(h*nu/(k*T)) – 1.).

So gnuplot is now my standard calculator, rather than Python interactive mode. The Python fans will now tell me that there is a Python version of gnuplot. Indeedy… but thats straying into the graph plotter shoot-out territory…. Watch this space.


7 Responses to Gnuplot calculator

  1. I just asked how to do a similar thing in the python interpreter and got an answer here:

    So, with ipython at least it appears to be possible to get this behavior. (The workaround in the standard python interpreter is still rather cumbersome.)

  2. Jim Geach says:

    I guess the most up-to-date, semi-interactive plotting environment for Python is matplotlib… however I still like the flexibility of the Python binding to PGPLOT (

    It’s great for making ‘real’ plots, but I played around with trying to make it a bit more interactive (at least in the Python interpreter) by adding a further layer on top of it that sequences underlying PGPLOT routines in more of user-friendly way. For example you can do stuff like:

    plot.lambda_function(lambda x: sin(x),colour=’red’,weight=3)

    for simple (lambda style) functions, and even generic funcs(x,p) if you want… and there’s other stuff in there too, mainly for plotting data, images, etc.

    I can make it available if anyone’s interested – I’ve always meant to.

  3. Mike says:

    If you just want numerical results, ie you don’t need a graphical output, then have a look at either of the two ‘Generic’ calculators at
    They both give you a full arithmetic parser/calculator in a single text box.

  4. […] am going to do it in installments … Just over a year ago I wrote a couple of posts (here and here) about looking for calculators that hit a sweet spot between laborious button-pushing GUI and full […]

  5. Molozonide says:

    There is an ancient UNIX terminal calculator called “desk calculator” for this exact purpose. It can be summoned by the command `dc` or `bc`. It will handle almost all basic calculations and features variable substitutions. One can set the default precision. There are built in functions for sqrt, sin, and arctan, and a few others. However, it won’t handle functions as far as I know.

  6. Can I recently say what relief to locate somebody that actually knows what theyre dealing with on the internet. You definitely learn how to bring an issue to light and earn it important. Workout . need to see this and understand why side from the story. I cant think youre less common since you absolutely contain the gift.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: