down

Exercise 3: Implicit Equations

 


This is an exercise in using IDL for program development, plotting and debugging (finding errors in) a program. These particular errors are "planted", but are typical of the types of errors you will almost certainly make when you write your own programs.

You will first get acquainted with basic use of IDL, then work mainly with IDL's development and debugging environment IDLDE.

The questions today are organised slightly differently. There are a number of links to "hints" that you may use if you get stuck. Often the answers were discussed during the lecture, and/or can be found by looking in the PDF lecture notes. However, the hints are not very expensive, so don't worry too much about using them.

Pick up your bonus points here!   Credits: 6/6

Subsections

approx time

Updating the exercise files

1 min

Working with IDLDE

30 min

Testing and debugging

45 min

Improving the performance

60 min

Home Work

1 hour

NOTE: This exercise tends to have a relatively large spread in the time it takes to complete for various people. To avoid getting into trouble with time:
  1. Use at most 45 minutes on the item "Working with IDLDE".
  2. Read ahead in the instructions below, more than just a few sentences.
  3. Look (again ;-) in the PDF lecture notes if get stuck; often the answer is there, or is hinted at there.
  4. Or, ask the exercise teacher for help if you get stuck; he will tell you essentially the same things that are in the PDF lecture notes.
  5. Or use the hints; they can be a good bargain!


down top  Updating the exercise files

[about 1 minute]

To update the exercise files (which includes getting the files for this weeks exercise), do

    cd ~/ComputerPhysics
    cvs update -d

In case of problems, see the CVS update help page.


down top  Working with IDLDE

[about 30 minutes]

The purpose of this part is to introduce you to some basic IDL commands and to IDLDE, the IDL Development Environment. Start the IDLDE, either from the dropdown menus, the icon on the desktop or by typing "idlde" from a command prompt. This opens a window with several frames. The only one relevant right now is the one titled Command Line, located at the bottom of the window. Use the on-line IDL Basics (This is an old version, but the basics have not changed since 1997) and work through at least the first Section (PDF pages 9-12, document page nos 3-6); trying out the examples on the screen

If you have time (within the 30 minutes), look at some of the other Sections in the manual as well. Some other time, browse the first few Chapters in Getting Started with IDL.

The roles of journal files (with names ending in .jou) and procedure files (.pro) are explained in the Lecture Notes, and in this hint:

Summary of IDL journal files and procedures   Credits: -1/-1

Here are some follow-up questions:

Let's assume 060915.jou is an IDL journal file, prog.pro is an IDL main program, doit.pro is an IDL procedure with two arguments, and fun.pro is an IDL function with three arguments. Indicate if the following are syntactically correct or incorrect, assuming the internal machinery knows how to handle it:      (scores +1 and -1)

IDL> @060915.jou correct
incorrect
Credits: 1/-1
OK
IDL> .run prog.pro correct
incorrect
Credits: 1/-1
OK
IDL> .r prog correct
incorrect
Credits: 1/-1
OK
IDL> @doit correct
incorrect
Credits: 1/-1
OK
IDL> doit,a,b correct
incorrect
Credits: 1/-1
OK
IDL> a=fun(a) correct
incorrect
Credits: 1/-1
OK

  From now on you will be working on material in the 3_Implicit directory, so you need to make sure that your IDLDE session is running in that directory. So,

Once the code compiles OK, it is time to test its various parts.


down top  Testing and debugging

[about 45 minutes]

The Implicit.pro file contains one procedure, NewT, and two functions, Ne_over_N and residual:

NewT
computes factors that only depend on temperature
Ne_over_N
computes the relative number of electrons, given the electron density
residual
is the function that vanishes when a consistent solution has been found. The exact form of the function may be changed, as long as it returns zero for the same physical solution. By changing this function in various ways one can improve the speed (reduce the number of iterations needed).

We first test if the NewT procedure works as it should:

NewT problem 1

NewT problem 2

NewT problem 3

NOTE: If, after having tried a number of changes, you become uncertain about what you really have changed, and you want to compare against the original, CVS is able to help. Just do, in a terminal window
    cd ~/ComputerPhysics/3_Implicit
    cvs diff

Ne_over_N tests

Now over to tests and illustrations of the Ne_over_N function. The solutions we are after are those electron densities N_e and total densities N that give
  Ne_over_N(N_e) = N_e/N
Let's look at this graphically:


down top  Improving the performance

[about 60 minutes]


top top  Home Work

[about 1 hour]

Spent a couple of hours of follow-up on the Lecture, studying the chapter in Numerical Recipes about root finding, and browsing the Fortran book.

After the exercise, it would be a good idea to continue reading some of the introductory sections of the Getting Started in IDL and IDL Basics manuals and the Building IDL Applications manual. Go through the material from the exercise; making sure you understand what is going on, by going back and forth between reading the manuals and the program text.

You may also want to try out some of the examples on screen.

If you're interested in history/stories; here is the story behind Murphy's law.


$Id: Exercise.php,v 1.16 2010/04/26 08:08:07 aake Exp $ aake@astro.ku.dk