Tuesday, September 25, 2012

Introduction to Gnuplot

Simple Plotting with Gnuplot

Gnuplot is a powerful command line driven plotting program that is available for Windows, Mac and linux (and others). It is freely available to install and use. The application has two main features: it allows us to interactively plot mathematical functions and data at the command line; and also to create scripts that can analyse data or just create hundreds of figure plots simultaneously.

The big advantage for scientists is the ability to quickly review results from numerical calculations. Rather than waiting minutes to load up a spreadsheet program and create a plot results can be viewed almost instantly.

Please see other posts [1] for how to install and use on different operating systems. In this tutorial we shall use a terminal on the linux based Ubuntu DE to demonstrate the commands. The commands themselves are the same regardless of which operating system we work on. For a full list of commands and a more indepth look at the program you can find the official docs here

Gnuplot Official Guide (pdf)

Open a new terminal and type gnuplot into the command line. You should see the following:


Now enter the following command, press return

plot sin(x) with lines

and you should see


Inputting other functions is relatively simple, the syntax is similar to that found on other popular mathematical programs such as matlab. You can also store parameters, create functions and change them interactively, for instance enter the following code

a = 1.4
b = 0.13
f(x) = a * exp(-b*x*x)
plot f(x) with lines

which appears on screen as


Now we can add labels, change the distance between tics, the range/domain, and add rename the key with the following


set xlabel "x"
set ylabel "y"
set xtics 4
set ytics 0.25
set xrange [-8:8]
set yrange [0:1.5]
plot f(x) title "My Function" with lines


Try experimenting with different functions and changing the properties of the plot. Next try plotting 2D and 3D data from files in the post " Plotting 2D and 3D data with Gnuplot ".

Thursday, September 20, 2012

Using WinEdt on UoM windows image

A Simple Latex File
Tex is a computer program that can typeset text and mathematical formulae. Latex is a markup language that uses tex as its typesetting engine. Basically this allows the user to embed commands within a text file that can be interpreted by latex to produce a high quality typeset documents. WinEdt is a latex integrated development environment (IDE) for windows, that means that you can both edit text files and produce typeset documents all in one program, it is available to download for free but only on a trial basis.
Click on the start menu at the bottom of the page and enter 'winedt' in the search bar, then click on the application.
Once the program has opened, go the file menu and select new.
Now you must save the file before you start editing, so go to save as in the main menu, move to a directory in which you wish to save the document.
Call the file something like "test.tex" or "helloworld.tex", with the file ending ".tex".
Now we can start writing our latex file. Latex commands are always preceded by a backslash, there are predefined commands and the user may also specify their own. There is also a certain structure that must be adhered to. Two of the most common commands are \begin{} and \end{}, that signify the start and end of an environment. Like a good story all latex files need a start and an end, and the document environment signifies the start and end of a document, so all files require \begin{document} and \end{document}. The other requirement is some information about the structure of the document that you are creating. This information must be presented in the preamble (before \begin{document}) with the \documentclass{} command. There are certain default options that can be used, article is a popular choice. For the most simple of latex files enter the following text:
\documentclass{article}

\begin{document}
test
\end{document}
Once the "tex" has been written, it must be compiled in order to generate a file that can be printed or viewed on screen. A standard file type to convert to is pdf. There are lots of ways to generate a pdf, one is to go directly from the latex file to a pdf (using the pdflatex command) or and another is by converting from tex->dvi->ps->pdf.
Select the pdflatex option for the menu bar:
Click on the pdflatex button to compile the document, and now you should be able to view the pdf you have created by
clicking on the adobe acroread symbol in the menu bar.