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:


Leftover Tasks from Session 4

Work on these at most for the first 30 minutes of the period.

  1. 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.
  2. 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).

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.

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!).

  1. 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?

  2. 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?

  3. You need to pick a reasonable value of Rmax. Justify your choice based on the eigen_tridiagonal.dat plot:

  4. 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 wave functions. 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).

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

  1. 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!).

  2. Compile and link the code eigen_basis using make_eigen_basis. This also compiles harmonic_oscillator.cpp. 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.
  3. 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?

  4. 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 is changed.)

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

  6. 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!)

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