Exercise 2: Hydrogen Ionization |
Hi,
This exercise contains ready-to-run IDL, Fortran-90, Maple and Mathematica programs, and is a jump start to programming in these four environments.
As discussed in the lecture notes, there are several purposes with this exercise:
Each of these three tools is useful to have in your mental "toolbox", and the overall purpose of all of these exercises is basically to help you learn how to use them efficiently.
|
Subsections | approx time |
---|---|
Getting the exercise files with CVS |
|
IDL test of 2nd order polynomial root |
45 min |
IDL solution of the ionization problem |
|
Fortran-90 (with IDL-plotting) |
|
Maple - Mathematica |
|
Be nice ... |
|
IDL demos |
5 min |
Home Work |
|
Getting the exercise files with CVS |
[about 5 minutes] |
We will be using CVS (Concurrent Versions System) to distribute the exercise files. Later, we will look at CVS in more detail, but for now it is only a "black box" method to get the files you need for the exercise.
To get the files, do the following
cd ~/ComputerPhysics (or whereever you have it) cvs update -d
NOTE: If you get a message such as "permission denied" you need to do "cvs login" and then repeat the "cvs update -d" command.
This updates the directory with the files needed for this exercise, which end up in the directory ComputerPhysics/2_H+He.
IDL test of 2nd order polynomial root |
[about 45 minutes] |
We will first use idlde, the 'Development Environment' for IDL (Interactive Data Language), to look at why there is a problem with computing one of the roots of a second degree polynomial with the standard high-school formula. Some of you all ready know this problem from Dat-f, it should therefore be relative easy to answer the questions and you should mainly spend the allocated time to learn about the new working environment.
cd ~/ComputerPhysics/2_H+He # Try hitting the TAB key instead of typing the whole thing idlde & # The "&" starts the command "in the background"
NOTE: If this results in an error message, just use "idl" instead of "idlde". No fancy windows, but you don't need them this time.
Shortly after idlde asking where to locate a workspace. This is a directory where it stores information about the state of idlde. This information is used to restore the working environment you used last time running idlde. Choose to make a new directory (e.g. called workspace) inside the present exercise directory and use this one.
A window with several panels, buttons, and menus appears. Take a few minutes, look around, and familiarize yourself with the various elements of the window, but don't be alarmed if you initially only have a vague idea about what many of them might be good for. Later on, you should spend time reading introductions and documentation, but for now we are just going to use it.
IDL> a=0.5 IDL> c=-0.5 IDL> b=1. IDL> print, (-b+sqrt(b^2-4.*a*c))/(2.*a)
IDL> b=1e1 & print, (-b+sqrt(b^2-4.*a*c))/(2.*a)
IDL> b=1e2 & print, (-b+sqrt(b^2-4.*a*c))/(2.*a) IDL> b=1e3 & print, (-b+sqrt(b^2-4.*a*c))/(2.*a) IDL> b=1e4 & print, (-b+sqrt(b^2-4.*a*c))/(2.*a) IDL> b=1e5 & print, (-b+sqrt(b^2-4.*a*c))/(2.*a) IDL> b=1e6 & print, (-b+sqrt(b^2-4.*a*c))/(2.*a) IDL> b=1e7 & print, (-b+sqrt(b^2-4.*a*c))/(2.*a)
|
IDL> b=1e5 & print, (-b+sqrt(b^2-4.*a*c))/(2.*a), 2.*c/(...)
IDL> b=1d5 & print, (-b+sqrt(b^2-4.*a*c))/(2.*a)
|
IDL> b=1e17 & print, 2.*c/(...)
|
What could one do about it, in addition to making b double precision? Try to figure it out, before taking this free hint? (No minus points - just your selfsatisfaction if you can figure it out without the hint!-:).
IDL solution of the ionization problem |
[about 40 minutes] |
Next, we will look at a ready-made IDL program, where the problem with computing one of the roots of a second order polynomial is acute.
Questions:
f = -1 + sqrt(1 + epsilon)
|
|
Fortran-90 (with IDL plotting) |
[about 45 minutes] |
The 2_H+He/H+He.f90 program solves
the same problem, but since
Fortran is a language that requires compilation (i.e., turning the
program text into a binary,
executable file), there are more steps to go through. Also, in order
to plot the results, data
must be written to a file and then read with IDL.
At this point you need to edit a Fortran text file. Most of you
probably already have a
favorite text editor that you can do it with. If not, you may want
to try kedit,
nedit, gedit, kate or possibly
emacs / xemacs -- you may then find Nina
Jansens 45 minute emacs tutorial
useful - or vim --
here
is an introduction by Bo Milvang.
cd cd Co<TAB>/2<TAB> (where <TAB> represents the TAB-key; see tab expansion) ifort H+He.f90 (or use gfortran, g95, or whatever Fortran compiler you have ...) ./a.out
IDL> cd,"ComputerPhysics/2_H+He"
|
Maple / Mathematica |
[about 30 minutes] |
There are two competing softwares for doing analytical mathematics, namely Maple and Mathematica. Both are available at NBI and are used by different research groups. Here you have the possibility for trying out both packages. From the CVS download files for both packages are included. It will therefore be simple for you to compare the two competing softwares. To start Maple or Mathematica from an xterm prompt, do
cd ~/ComputerPhysics/2_H+He # Use the TAB key instead of typing the whole thing xmaple & # or mathematica &
NOTE: It may take some time for the Maple or Mathematica window to appear. |
Use the File -> Open menu to find and open the Quadratic.{mw/nb} and H+He.{mw/nb}
notebooks in the 2_H+He subdirectory.
NOTE: To keep things simple, in this exercise Mathematica is only used to calculate and plot the given expressions. For the more adventurous student, there is also the Ionization.nb notebook, where Mathematica is used to actually derive the expressions, and where it is shown that the problem with numerical precision also occurs in Mathematica. |
Mathematica documentation (including the full Mathematica Book) is available on-line, from the HELP menu in the upper right hand corner of the Mathematica window.
Be nice to yourself, and to us ... |
[about 5 min] |
IDL demos |
[about 15 minutes] |
If you still have time left at his point; use it to play with IDL, Maple or Mathematica (if you don't have time left, do this as part of the home work). There are a number of IDL demos, that may be accessed by typing demo at the IDL prompt.
Home Work |
[about 2 hours] |
After you are finished with this exercise, use time at home or Wednesday to study and compare the IDL, Fortran-90, Maple and Mathematica programs. A good exercise might be to trace the use of one-dimensional and two-dimensional variables in the programs, and mark them by single and double underlining on your hard copy. Use the variable trace pane to browse the variables in IDL. Use analogy reasoning to figure out the corresponding properties of the Fortran-90, Maple and Mathematica variables.
Take ample time to review relevant sections (on assignments,
declarations, Parameters,
etc.) in one of the Fortran book. Familiarize yourself with IDL, by
accessing the on-line PDF
copy of Getting
Started in IDL. If / when you have
installed IDL, you should also familiarize yourself with where
to find the IDL help and documentation files on your own
PC.
CHECKPOINT: The programs in this exercise are ready-to-run, not to make this a trivial exercise, but to give you some examples to look at, OK? :-). Studying working programs helps you to pick up a new computer language much more rapidly... |
Note that you may use CVS from home, either from a terminal window under Linux, or from the WinCVS and MacCVS graphical user interface clients, to check out and maintain a consistent set of exercise files on your home computer or laptop. There will be more information about this later, but if you are eager to try this out you may want to start out with the CVS tutorial. With access to a cvs command line (e.g. from Linux), the CVS commands used in the exercises should work from home as well.