down

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:

  1. To provide a simple example of the ionization of atoms. Hands-on experience with the solution of physical problems is the fastest way to get a basic feeling for "how it works".
  2. To illustrate that even a seemingly straightforward evaluation often contains "numerical traps", such as
  3. To introduce you to the three (four) language environments that we will be using in the rest of the course:

    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.


down top

Subsections approx time
Getting the exercise files with CVS
5 min
IDL test of 2nd order polynomial root

45 min

IDL solution of the ionization problem
40 min
Fortran-90 (with IDL-plotting)
40 min
Maple - Mathematica
30 min
Be nice ...
15 min
IDL demos

5 min

Home Work
2 hours


down top 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.


down top 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.


down top 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:

  1. The problem with numerical precision occurs in an expression equivalent to (in IDL syntax)
    f = -1 + sqrt(1 + epsilon)
    
    For small values of epsilon, f is approximately equal to epsilon
    epsilon/2
    sqrt(epsilon)
    Credits: 4/-4
    OK

  2.  
    If the square root function has 7 significant digits, and epsilon is equal to 2 10^-4 (and also has 7 significant digits), how many significant digits are there in f? (compare the error in the result with the size of the result) Credits: 4/-4
    OK


down top   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.

Please upload the corrected (and verified) Fortran file Locate and upload your H+He.f90 file: Credits: 4/0
OK


down top 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.


down top Be nice to yourself, and to us ...

[about 5 min]


down top 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.


top 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.


$Id: index.php,v 1.1 2010/04/25 23:58:51 aake Exp $