Phys 291 - Project: Finite square well

Project description
My project in PHYS291 has been to make a program for solving a quantum mechanical finite square well. Previously this semester, I solved this using matlab, and I wanted to make an improved version using C++ and Root. I wanted to make it possible for the user to choose different values for the potential depth and size while running the program. I also wanted to explore some of the possibilities of using Root as GUI.

Program Description
The program buttonTest.C is a GUI where the user can choose different values for the potential well depth and size, and see the immediate changes in the graphical display of the energies and wavefunctions. The program uses the class Wavefunction definied in psi_class.C. This is a class with methods for calculating the Hamiltonian, eigenvalues, eigenvectors and wavefunctions of set potential values, and methods for plotting all this information in a TMultiGraph.

The program filling.C is my first attempt to make a plot of the potential well and wavefunctions. The code runs and makes a plot, and was the basis for the "nicer" version of making a wavefunction class.

Program code
Get project.tar files here.

filling.C : The first program version lets user define potential depth, and well sizes and then makes a plot of the energies and wavefunctions. There is no use of functions or methods, so code looks a bit messy.
psi_class.C : This version defines a class Wavefunction with methods for calculating the Hamiltonian matrix and making plots
buttonTest.C : A GUI, with the possibility of choosing potential depths, and well sizes. Displays the graph in GUI.
eigenvalue.m : Matlab program used as a basis for the root program.

Theory
The one-dimensional motion of a particle with mass m in a potential V(x) is described by the particles wavefunction. The wavefunction is found by solving the Schrodinger equation. For a finite square well, (a particle trapped in a box with finite potetial walls) the potential is given as

Approximate numerical solutions may be calculated by the matrix representation of quantum mechanics. To do this one encloses the finite square well of size a, in an infinite square well of size L, making the potential

On the interval from -L to L,

, are the solutions of the infinite square well, form a complete set. This means that an arbitrary function f(x) with boundary conditions f(-L)=f(L)=0 can be expanded in terms of the functions i.e.

Let f(x) be the wavefunction, and assuming L>>a, the Hamiltonian of the finite square well is H=H_0+V(x) where H_0 is the Hamiltonian of the infinite square well with energies

Inserting the wavefunction into the eigenvalue equation

and projecting from the left with we obtain a system of equations for the Hamiltonian,

This system can be written on matrixform Hc = Ec, which can be solved numerically. The eigenvectors c, are the coefficients of the wavefunction

with corresponding eigenvalues E.

Calculation of the matrix elements

where

gives: For m = n, m and n are even:

For m = n,m and n are odd:

For m and n even:

For m and n odd:

Results
Using my matlab program, (eigenvalue.m) as a model, I made a plot for the potential well. Figure 1 shows the output of my matlab program.

I then needed to make the Hamiltonian matrix for the potential well, which was done quite easily as I used the same method as in my matlab program. The challenge arose in calculating the eigenvalues and eigenvectors, as the method for this in Root did not return the values and vectors sorted by size.

My first solution to this was to loop through the eigenvalues and save the index of the bound energies in an array, and use the indexes to access the correct values. I then made graphs of the energies and wavefunctions. Adding all the graphs to a TMultigraph made the display better. This is the file filling.C.

Having managed to make a plot similar to my matlab program, I wished to make the code more efficient and readable, so I made my wavefunction into a class, (psi_class.C). For this I needed to have the eigenvalues and eigenvectors sorted from lowest energy to highest. With help from Ladislav I got a method for sorting my eigenvalues and vectors. Using this I managed to draw a TMutligraph including wavefunctions and energies for all the bound states of the system. Figure 2 and 3 shows plots of two wavefunctions, one with V=1 and the other with V=2.

I then wanted to make a graphical user interface for choosing potential depth and size and displaying my graph. Modifying a test file from the root tutorials, buttonTest.C, I managed to make radio buttons for choosing potential values. The choices were displayed on a separate TCanvas. After receiving a tip from Boris, I was able to use a TEmbeddedCanvas to display my graph on the user interface, and make an immediate update when a new radio button was selected. The GUI is displayed in figure 4.

Conclusion and outlook
This course was my first time using Root, and I have seen some of the possibilities and limitations that Root has to offer. I have experienced that calculating and sorting eigenvalues and vectors was a bit more complicated using root then in matlab. Using Root to make and display graphs from a formula, gave a much better and more flexible result then in matlab. And the possibility of using root as a GUI, made my result nicer and more accessible for the user

Acknowledgements
I would like to thank Boris Wagner and Ladislav Kocbach for all help and useful tips, both during computer labs and while working on the project.