An introductory CLI-oriented extrema tutorial:
This is a 25-minute tutorial, geared toward the second-year Physics majors.
It does not offer a comprehensive survey of the capabilities of extrema,
but focuses instead on plotting and basic analysis of experimental data.
More comprehensive introductory and reference material is available in the
Documentation section below.
-
-
Starting extrema can be done by clicking on its icon in the applications menu,
or by typing extrema & in a terminal window (the optional &
symbol detaches the extrema child process from the terminal and runs it in the background).
When extrema launches it opens up two windows: "Analysis Window" (AW) and "Visualization Window" (VW),
each with its own set of buttons, menus, and functionality. A good working
arrangement of the windows on your desktop is shown here:
where the third window is a simple text editor (TE) that will be used to write extrema command macros.
-
-
If you have never run extrema before, start by
typing the following into the Command (input field) of the Analysis Window (AW),
press Enter on the keyboard and follow the prompts:
@demo
-
-
Type the following into the Command (input field) of the AW:
clear
x=[1:8]
y=[0.05;0.10;0.14;0.19;0.25;0.30;0.34;0.40]
graph x,y
Your Visualization Window (VW) should be showing the graph of y vs. x!
The above data could have been something like time and distance from an air track experiment.
In fact, we should have also entered the error bars at each data point, like this (continue in AW):
dy=[0.02;0.07;0.01;0.04;0.05;0.10;0.02;0.04]
clear
graph x,y,dy
We have used clear to clear the plot and start a new one with the next graph command.
-
-
You can immediately see that the dependence is roughly linear, but we should test that. Also, we should
properly label the axes and follow the usual convention of reserving discrete plot points for the
experimentally measured data, and continuous curves for functions, like lines of best fit. The following
commands accomplish that:
set xlabel `Time, s'
set ylabel `Distance, m'
set plotsymbol -15
clear
graph x,y,dy
Now each data point is indicated by a filled diamond (the plotting character No.15),
and there is no line connecting the data points (the minus sign in front of 15).
Note that the string-opening quote ` (top left on the keyboard) we used in
specifying labels is not the same as the string-closing quote ' ;
this is the recommended use that will help extrema sort out complex
composite strings later, so it's good to get into this habit now.
-
-
Now we are free to use a line to indicate a theoretical model that fits this data.
From the way we generated our data (air track) we expect a linear dependence.
Let's fit the data to a linear expression:
scalar\vary a
fit y=a*x
The output generated by extrema, among other things, tells us that the best value for
the scalar parameter a is 0.0493+/-0.0038. The error in the fit is given by the standard deviation
(the E2 parameter), and there are some other useful numbers reported which we will ignore for now.
Armed with this best fit, we can add a "theoretical" line to our experimental plot:
set plotsymbol 0
graph\overlay x,a*x
Two points of interest here: we set the plotting character to none and the line through the points to on,
and then we used a switch graph\overlay to add the second graph to the already existing one.
Looks pretty cool.
-
-
Typing commands manually is not difficult, but re-typing them after a mistake or a change in data
quickly grows tedious. Macros provide a way out. When you typed @demo at the very beginning,
you actually already executed an extrema macro demo.pcm (distributed with the program),
and now it's time to write your own.
In the text editor (TE) window, copy-and-paste all of the commands used so far, and save this as a
simple text file graph2d.pcm :
clear
defaults
x=[1:8]
y=[0.05;0.10;0.14;0.19;0.25;0.30;0.34;0.40]
dy=[0.02;0.07;0.01;0.04;0.05;0.10;0.02;0.04]
set xlabel `Time, s'
set ylabel `Distance, m'
set plotsymbol -15
set %plotsymbolsize 1.5
graph x,y,dy
scalar\vary a
fit y=a*x
set plotsymbol 0
graph\overlay x,a*x
A sharp-eyed observer will notice two small changes: defaults command at the beginning of the macro
ensures that we always start from the same known settings, and are not adversely affected by some settings
left over from a previously-run macro; and the command set %plotsymbolsize 1.5 increases slightly the size
of the plotting symbol, to 1.5% of the screen width, up from the default size of 1%. Many extrema
settings can be changed this way to make the graph look just so, this is just a small example.
In AW, type @graph2d to execute your macro.
Also in AW, press the $\fbox{?}$ button at top right to bring up extrema's Help facility,
and do a search for plotsymbol ; explore the few helpful pages that will show up.
Note: extension .pcm is the default, and is not necessary to type it; @ is actually a shorthand,
you can also type execute graph2d (or any unambiguous abbreviation, e.g. exe graph2d )
to achieve the exact same outcome.
-
-
Our macro in the previous step contained everything it needed, including the data vectors themselves.
To analyze another set of data from a similar experiment one would have to edit this macro file.
Instead, let us separate the data into its own file; then for another data set the macro file could remain the same,
and one would only need to apply the same macro to a different data file.
In the TE window, create a new file (use the $\fbox{+}$ button) and enter the following data into it:
1.0 0.05 0.02
2.0 0.10 0.07
3.0 0.14 0.01
4.0 0.19 0.04
5.0 0.25 0.05
6.0 0.30 0.10
7.0 0.34 0.02
8.0 0.40 0.04
i.e. the same data as we used before, now entered as three columns. Save this file under the name
e1.dat (this is our first "experiment") in the same directory as graph2d.pcm .
Modify graph2d.pcm as well, and replace the three lines that define vectors x, y, and dy with one line that reads:
read ?1 x,y,dy
meaning "read the data from the file whose name is contained in the parameter No.1 (?1) on the command line into vectors x, y, and dy".
Back in AW, type @graph2d e1.dat to run your "universal" macro and passing the name of the data file to it.
For another set of data you could generate a similar graph with a single command, by specifying a different data filename.
Test your understanding of the above macro by modifying it to allow passing the
plotting character code as the second parameter. Within the macro you would refer
to it as ?2 and the extrema command would be:
@graph2d e1.dat 16
to use filled triangles (plotting character 16) instead of the diamonds we used before.
-
-
Instead of plotting experimental data, physicists often like to "doodle"
with mathematical expressions. Sometimes it's an attempt to visualize a
solution to some differential equation, to see if it makes sense; or it's
a first step in finding the nulls of a complicated polynomial; possibly
it's a quick way to look up a family of standard mathematical functions.
Programs like maple or mathematica do these
things extremely well, and extrema, too, has ample
capabilities, and is much faster. Try this in AW:
clear
defaults
x=[0:3*Pi:0.01]
y=x**2*exp(-x)
set curvecolor blue
graph x,y
and you can see right away that the function $y(x)=x^2 e^{-x}$ has
a maximum value of about $0.55$ near $x=2$. Above commands generate
a vector $x$ from 0 to $3\pi$ in tiny steps of $0.01$, then calculate and plot
$y(x)$. We can see what the first derivative looks like in this way:
set curvelinetype 9
set curvecolor red
graph\overlay x,deriv(x,y,`interp')
where we stipulated that the numerical derivative be calculated
using the method of interpolating splines. There are other options,
and the help facility has the full description of the special function deriv() .
For the derivative, we set the line type to something other than
the default value (1=default=single solid line, 9=dotted line, etc),
and use a different colour.
-
-
Numerical integration, differentiation, spline interpolation,
a large library of special functions, ... [would you like to know what
the fourth-order Laguerre polynomial looks like? - try y=laguerre(4,x) ]
- these are all things that extrema does with ease.
It is pointless to list its capabilities here,
this is what the manuals are for, see below.
Remember, you don't have to know all commands, just get the feel
for where things are in the manual, to be able to look them up
quickly when needed. In comparison with other plotting and
data analysis software, extrema has a relatively
simple and natural syntax, and prides itself at having a much shorter
learning curve, an important consideration for student use. On the other
hand, it has "long legs" in research use (see the Testimonials link on the left)
and this makes the small initial time investment worthwhile.
Documentation
|