780.20: 1094 Session 5
Handouts: New: eigen_tridiagonal.cpp printout,
eigen_basis.cpp printout, harmonic_oscillator.cpp
printout, nan_test.cpp printout, and square_well.nb Mathematica notebook.
From session 4:
eigen_test.cpp printout and GSL Eigensystems documentation.
Your goals for this session:
- Finish some leftover Session 4 tasks.
- Take a first look at your shell start-up file.
- See some examples of nan's and inf's.
- Use the eigen_tridiagonal program to look at eigenvalues
of the harmonic oscillator potential.
- Find the lowest bound-state eigenvalues of two
familiar potentials using the eigen_basis program.
- Examine (and try to understand)
how the accuracy of your results depends
on the size of the harmonic oscillator basis and the choice of the
basis parameter b.
Please work in pairs (more or less).
The instructors will bounce around 1094 and answer questions.
Leftover Tasks from Session 4
Work on these at most for the first 30 minutes of the period.
- Pointer Games. The important part of this exercise
is not understanding pointers in detail but to successfully
modify a code based on an example. For now, just look at the
derivative_test_new.cpp code, which is a solution to this exercise,
and see if you have questions.
- Linear Algebra with GSL Routines.
You'll see the same things in Session 5. If you are running short
of time, just go through the discussion in the Session 5 notes.
Optional: Aliases in Your Start-up Shell
The shell is the program you type to at the command line.
If you are using Linux, you are most likely using tcsh. If you
are using Cygwin, you are using bash. There are many good things
to learn about the shells. Today we'll just learn about aliases.
Just follow the corresponding instructions for bash (tcsh).
- Bash (tcsh) aliases. The .bashrc (.cshrc.more) file
sits in your home directory and
is "sourced" when you start an interactive terminal.
Take a look at the sample .bashrc (.cshrc.more) file printout (these files,
without the ".", are
in the session 5 zip file). Copy any aliases of interest to
your own .bashrc (.cshrc.more) or the whole thing using cp bashrc
~/.bashrc (cp cshrc.more ~/.cshrc.more)
if you don't have one already.
Activate the changes with the
command: source ~/.bashrc
(source ~/.cshrc). Try some aliases such as
ll (for "long listing") and df,
which shows info about the disk file system.
- Create your own alias. If on Linux, make up an alias
to start up gnuplot from
If on Cygwin, make an alias to change from your start-up
directory to your working directory. What line
did you add to the start-up file?
Nan's and Inf's
Just a quickie: Take a look at nan_test.cpp,
use make_nan_test to create nan_test and then run it.
- What do you think the result of 0.*(1./0.) will be? Predict
and then modify the code to check it out. [Note: Use the
variables "numerator" and
"denominator" to calculate (1./0.).]
Bound States by Matrix Diagonalization in Coordinate Representation
The program eigen_tridiagonal.cpp uses the GSL library routines
explored in eigen_test.cpp (session 4) to find the eigenvalues and
lowest eigenvector of the harmonic oscillator using a method described
in the Session 5 notes. With the units here, the lowest eigenvalue
should be (3/2)hbar-omega = 1.5 (read comments in code!).
- Using make_eigen_tridiagonal,
compile and run the code a few times to see how it works.
Try various values
of Rmax and N such as Rmax=3, N=20 or 50
(make a chart here of Rmax, N and the two
lowest eigenvalues for five pairs of Rmax,N).
How can you verify that the code is working?
- Change the code so that only the lowest few eigenvalues are printed
out. Look at the output file eigen_tridiagonal.dat and plot it with
gnuplot. What is this function? The value at r=0 is not given;
what should it be?
- You need to pick a reasonable value of Rmax. Justify
your choice based on the eigen_tridiagonal.dat plot:
- For your choice of Rmax, try N = 4,8,16,32,64,128,256,512,1024.
How does the relative error for the lowest eigenvalue scale
with N? Attach an appropriate plot to validate your answer.
Bound States from Diagonalizing the Hamiltonian in a Basis
The program in eigen_basis.cpp
uses the GSL library routines to diagonalize (i.e., to find the
eigenvalues and eigenvectors)
a Hamiltonian matrix in a basis of harmonic oscillator
You may want to refer to the GSL handout on eigensystems (there is also
a printout of eigen_basis.cpp).
The eigen_basis program uses units in which the particle mass is 1 and hbar=1.
The program asks you to choose
The parameters of the potentials are fixed in the code.
The eigenvalues for the Hamiltonian matrix are written to the terminal
sorted in numerical order (as opposed to
absolute-value sorting, which was used in eigen_test.cpp).
The corresponding eigenvectors are generated but are not printed out
(that is, the print statements are commented out).
- a potential (Coulomb or square well);
- the parameter b for the harmonic oscillator basis
(see harmonic_oscillator.cpp for the definition);
- the number of basis states to use.
The Coulomb potential is defined with Ze2=1,
which means that the Bohr
radius is also unity. This means that the exact bound energy levels are
given by En = -1/2n2, with n=1,2,...
The square well potential is defined with radius R=1 and depth
V0 = 50. You should find that there are three bound states.
Here are some subgoals. There won't be time for everything
(as usual) but you'll have a chance to finish them as part of a future
- Run the Mathematica notebook square_well.nb (make sure you
understand what it is doing; e.g, look up FindRoot in the Help
Browser). Find the bound-state
energies for the square well parameters used here (you need to change
the notebook parameters!).
- Compile and link the code eigen_basis using make_eigen_basis.
Run it a few times with each of the potentials
to get familiar with it. If you try too large a basis size,
the run time may be too long (so start small!).
Look through the printout to see the basic idea of how the code works
and find where the
equation for the matrix element is implemented.
- Based on the "exact" results from Mathematica,
which predicted eigenvalue(s) do you think are most reliable?
Which eigenvalues are calculated most effectively,
those of the Coulomb potential or the square well potential?
Why do you think this is?
- You have under your control the size of the basis (i.e., the
dimension of the matrix) and the harmonic oscillator parameter b (see
harmonic_oscillator.cpp for the definition). For a fixed basis size
(pick one that reproduces the ground state reasonably), how do you
find the optimum b? (Hint: think gnuplot!) Can you qualitatively
(or semi-quantitatively) account for your
result? (Think about the potentials and guess what the lowest wave
functions will look like and what changes about the basis when
the harmonic oscillator parameter b
- If you now fix b (if you have time you can
consider two or three different values in
turn), how can you find how the accuracy of the ground state energy
scales with the basis size? Make an appropriate plot.
- Look at the code.
How could you make it more efficient? (What do you think
is the limiting
factor based on the scaling of the time with the size of the basis?)
For example, could you speed it up by almost a factor
of two? (Hint, hint!)
- How would you find the wave function that corresponds to
a given state (e.g., the ground state)?
Add code to generate the lowest wave function for the lowest bound
state (hint: it involves the eigenvector).
780.20: 1094 Session 5.
Last modified: 09:00 am, January 25, 2010.