Phys 291 - Project: The Hydrogen Wavefunction

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

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

Program code
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[1]


Where

Is the associated Legendre polynomial, with

It's Laguerre polynomial.

The spherical harmonics term[2]

With

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



And

,

Leaves us with the constants for given n, l, and m quantum numbers:

And the terms dependant on r, theta and phi, become:

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

Conclusion
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 [3]). 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.

Acknowledgements
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[4] as a guidance for better understanding of the examples, as well as html layout.

Sources

[1]Griffiths, David J.(2017). Introduction to Quantum Mechanics. 2nd ed. Cambridge University Press, p.152

[2]Griffiths, David J.(2017). Introduction to Quantum Mechanics. 2nd ed. Cambridge University Press, p.136-139

[3]Brandt, Siegmund and Dahmen, Dieter.(2001) The Picture Book of Quantum Mechanics. 3rd ed.Springer, New York, p.260-270

[4]https://folk.uib.no/imc001/

General code sources and documentation:

https://root.cern.ch/doc/v608/SpecFuncMathMore_8cxx_source.html

https://root.cern.ch/root/htmldoc/guides/users-guide/WritingGUI.html

https://root.cern.ch/root/htmldoc/guides/primer/ROOTPrimer.html

https://folk.uib.no/imc001/