I decided to make a GUI where a user could choose displayed values of the quantum numbers n, l, and m, and have the program calculate and display the probability density for the corresponding wavefunction of the electron in a hydrogen atom.
The file Window.cpp is my GUI. I wanted the UI to only display allowed combinations of n, l and m, but was unable to find a command to update the frame after a quantum number is selected. The for loops for the dynamic creation are still in there as legacy comments. The other file, Wavefunction.cpp, takes input from Window.cpp, and calculates the probability density, for several x, y and z coordinates, with given n, l, and m quantum numbers.
My code and this html will be available in a zip file here
Theory The normalised wavefunction for an electron in a hydrogen atom is the following
Is the associated Legendre polynomial, with
It's Laguerre polynomial.
The spherical harmonics term
The associated Legendre, and
It's Legendre polynomial.
We are after the absolute value squared of the wavefunction, giving us the probability density. This gives us the following equation:
To make this simpler for my program, I decided to divide this into two parts
It's important to note here, that since we're dealing with the absolute value squared then
Leaves us with the constants for given n, l, and m quantum numbers:
And the terms dependant on r, theta and phi, become:
The plots are not representative of anything, and I included a picture just to show the GUI.:
n = 1, l= 0, m = 0:
There is something odd about both the assoc_laguerre and the assoc_legendre functions i used from SpecFuncMathMore. When calling the assoc_laguerre on its own, it returns values fine, but inside my program calling it with l = 2, it returns 0, always. And the assoc_legendre will crash if called with a y value higher then 1 (on its own), but somehow functions fine when called with a y value higher then 1 inside my program. There is something off with the maths.
Because this went a little wrong, I decided to also include a screenshot with the graf beeing a polar graph instead of a Graph2D.
I've had some really odd distributions here. The program only gives reasonable output if run with (seemingly) the wrong math. And even then, it gives no output if ran on expected non-donut, or ball, shaped distributions. (Expectations from ). There is something wrong with the math in this project, but the GUI is functioning as intended. So I have learned a lot about ROOT and it's relationship with c++, which was the intension of the projcet.
Ladislav Kocbach and Boris Wagner have been of great help in debugging and general guidance. I also used several examples in root doccumentation which are sourced in Window.cpp (as well as below), and I used Ingrid McKibben Lofnes code as a guidance for better understanding of the examples, as well as html layout.
Griffiths, David J.(2017). Introduction to Quantum Mechanics. 2nd ed. Cambridge University Press, p.152
Griffiths, David J.(2017). Introduction to Quantum Mechanics. 2nd ed. Cambridge University Press, p.136-139
Brandt, Siegmund and Dahmen, Dieter.(2001) The Picture Book of Quantum Mechanics. 3rd ed.Springer, New York, p.260-270
General code sources and documentation: