083105109117108097116105110103032073110102105110105116121046046046

Our imagination is stretched to the utmost, not, as in fiction, to imagine things which are not really there, but just to comprehend those things which are there.

— Richard Feynman

It’s been a long hiatus since the last post but I hope to make it up for that here (with a source code instead of pseudo-code). So far, I have written about general algorithms. This time, I hope to explain the procedure involved in programming with an example where we will simulate quantum wells. I will assume that you have some basic knowledge of quantum mechanics and some basic programming experience with arrays and matrices. However, feel free to ask any question (no matter what) and I will do my best to clarify it.

We start by defining the problem. We want to study an electron trapped inside a one-dimensional quantum well. Within the quantum well, however, there are some potential barriers (think of other heavier ions) which influence the electron inside the well. We want quantum effects and so we use the Schrodinger equation:

Here is the second derivative with respect to space and is the potential inside the quantum well. We are interested in calculating the energy of the electron inside the well at ground states and excited states along with the probability distribution (equivalent to charge distribution) at each energy level.

For the first step, we want that the electron remains trapped INSIDE the quantum well. That can be done if we assume an infinite potential barrier outside the well. In other words, is zero outside the boundaries of the quantum well. This is good news because our “universe” is now confined to the quantum well.

We then look at what is required to be calculated — energy and probability distribution at each energy. The energy values are the “eigenvalues” and the probability distribution is given by the square of the wavefunction, the “eigenvectors”. There is one eigenvector for EACH eigenvalue. For more information, consult Eigenvalues and Eigenvectors. We now try to construct a matrix for the operator (Hamiltonian matrix) and find its eigenvalues and eigenvectors. Each eigenvector would be a column vector. We also divide space (one-dimensional) into grid points. The number of matrix elements in the Hamiltonian matrix would be the square of the grid points. Before we construct our matrix, we will first simplify the double differentiation as

Here is the distance between two grid points. It defines the “fineness” of the mesh. Looking at the dependence on , we see that the Hamiltonian will be zero everywhere except along the diagonal and two other “diagonals” forming a “tri-diagonal” matrix. Also, for the first row, we have and for the last row, we have because we have confined our “universe” to the boundaries of the quantum well. This is how our Hamiltonian matrix looks like:

The size of the matrix is where is the number of grid points. Once this is done, you can use Lapack routines to diagonalize the matrix and provide you with the eigenvalues and eigenvectors.

I have written a quick program in Fortran for a particular example of a quantum well of about 500 nanometers and a potential barrier of -0.1 milli-volts between 175 and 325nm from the origin. The source code is provided here: qu_well

To compile, you will need Lapack routines. Download the required packages and you can compile this source code. If you use Linux with gfortran, you can compile the code and run the program using:

gfortran -o qu_well qu_well.f90 -llapack -lblas ./qu_well

You can change the value of the potential, add more barriers or change the sign of the barrier. Different simple systems can be simulated with this code and you don’t need a specialized laboratory with very expensive lasers to understand how an electron behaves. In case the program takes too long to run, you can reduce the number of grid points. At the end of the program, there are four files written out which contain the eigenvalues, the eigenvectors (for each eigenvalue), the probability distribution (also for each eigenvalue) and the potential barrier inside the quantum well. By careful plotting of the probability distribution near the potential barrier, you will also see that the electron with energy (eigenvalue) LOWER than the potential barrier still has a non-zero probability of being there. This is called Quantum Tunnelling and is a well-known and experimentally proven concept in scientific literature.

The aim of this post was to show how computer programming can be used to solve many real-world problems. That’s why I didn’t sit and analyze the results. The focus in this post may not have seemed to be computer programming but that’s because a process of tackling any problem is best understood with an example. The requirement to change the partial derivatives as a finite difference and the method of creating the matrix is so that the code can easily written. Computers work in bits and so it becomes necessary to modify “continuous” data into “discrete” data like we did with the derivatives and the grid. The Hamiltonian matrix is a “continuous” matrix (because of the derivatives) which makes it an infinite-sized 2-dimensional matrix. To compute its eigenvalues and eigenvectors, we create a mesh and only take the Hamiltonian at those points. The derivatives then become differences of the value between those points.

Quantum Mechanics is not the only field where one needs to compute the eigenvalues and eigenvectors. These are required in many other fields like Image Processing, Geology, Statistics and Rotation Studies. But the process of tackling a problem using computers remains similar. We first have to break our problem into something a computer can handle. I hope that the source code provided helps you to connect the dots with how a basic one-dimensional quantum well problem can be tackled with. Trying to replicate the code and then rewriting (at least modifying) similar code would enable one to understand the process on a more “hands-on” level.

068111110101046046046032087104101114101032097109032073063