Using gnuplot to Graph Mathematical Formulas

This section shows you how to use gnuplot, an interactive plotting program by Thomas Williams and Colin Kelley. This program supports nearly 40 different printers and output devices, although you'll probably want to experiment with gnuplot using the X Window System and print your graphics using PostScript (see Hour 15, "Preparing Documents," for more information on how to do this).

Although gnuplot (no relation to GNU software, but supported and distributed by the Free Software Foundation under the GNU General Public License) is not the only mathe­matical modeling and plotting program available for Linux, it is included on your CD-ROM. You can find the gnuplot program under the /usr/bin/XllR6 directory.

The gnuplot program (see Figure 17.9) is a complete, interactive plotting program and was originally designed to graph math functions and data. In this regard it is somewhat similar to other commercial formula-interpretation and plotting programs. It can read and save files and has built-in help, so you can query the program while you use it.

Using gnuplot is simple. The program has five different command-line options (such as -mono or -gray to force monochrome or grayscale plots, and - clear and -tvtwm to clear the window first or place the window relative to the desktop), but many aspects of the program can be controlled interactively or as commands in a loaded gnuplot data file. One common use of the command line option is to control the point size (in pixels) of drawing lines using the -pointsize option, as in the following example:

# gnuplot -pointsize 2You can use and plot many types of mathematical expressions, and according to the gnuplot documentation, any C, Pascal, Fortran, or BASIC language mathematical state­ment can be used. For example, start the program at the command line of an X11 termi­nal window like this:

# gnuplot

After you press Enter, type in some variable values, such as the following:

gnuplot> y = -5 gnuplot> x = 8

Figure 17.9

The gnuplot program can help you visualize mathematical formu­las, spreadsheet data, and yes, even whales.


To plot an expression, such as (x*y)-(x+y), use the plot command, followed by the expression, like so:

gnuplot> plot (x*y)-(x+y)

After you press Enter, a new gnuplot window appears with a graphic of your expression. When you finish, type quit at the gnuplot prompt to exit the program. To load and plot sample datafiles, change directory to /usr/XllR6/lib/gnuplot/demo. Then, to display the data (as shown in Figure 17.9), use gnuplot followed by the name of a demo file, like this:

# gnuplot animate.dem

After you press Enter, you see a picture of the digitized whale, which starts swimming around the plot area of the gnuplot window. You can find more documentation, the gnuplot FAQ, and updates to the gnuplot program at gnuplot_info.html.Many, many different financial and math applications are available for Linux. This hour barely scratches the surface. You can find financial applica­tions that can help you manage investment portfolios, track stock prices, or aid in developing cost estimates for construction projects. You can also find hundreds of specialized programs you can use in solving special computing needs for other sciences. One of the best sites for perusing some of the best of these applications is http://SAL.KachinaTech.COM. You can also find a number of financial tools for Linux, along with source code, at http://