Project work Fys-292

By Irina Otdelnova

Visualization of hydrogen-like orbitals for
atomic physics using MATLAB

Problem definition

The task of the program is to visualize wave function for hydrogen-like
atoms. The program creates two windows - one with interactive controls
for the program and another one - for the figure of the wavefunction itself.
In the control window it's possible to change: range of plotting, the quantum
numbers n and l,
and also switch between plotting R(r) and r*R(r). The 'exit' button is
also present.

The programme is using the Symbolic Toolbox and the wavefunctions are
present as analytical expressions. These may be extracted by a user, if
necessary, as can be found in the listing.

Algorithm

1. Evaluate the wavefunction using the multiple symbolic derivation
for evaluation of Laguerre polynomials

Program listing: Part 1: User Interface

% VISN The program for visualization of radial function.
% Then the function is created symbolically.
% Finally its graph is shown in a window. The user
% has a possibility for controlling function parameters
% interactively.
% Some notes: I use first two MATLAB windows (Figure #1
% and Figure #2). If there are any open windows when the
% program is using, they will remain untouched.
% n and l given unphysical values, range initialized.
n=-1;l=-1;range=30;
nold=n;lold=l;
% An array of numbers starting from 0 to range with step of range/100
% These are the points at which the function is evaluated.
% This array is used later on for graphs.
x=0:range/100:range;
% Open graph window #1
F1=figure;
% Open control window #2 with sliders
F2=figure;
% Resizing the control window
pos=get(F2,'position');
pos(3)=300;pos(4)=250; % dimensions of the command window;
set(F2,'position',pos);
% Main Control Functions: Title, exit, type of displaying.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TitleF= uicontrol('style','text', ...
'string','Controls for Wavefunction Tool', ...
'position', [10 225 275 20]);
ExitBut=uicontrol('style','pushbutton',...
'string','EXIT','position', [10 200 50 20],...
'callback','close(F1);close(F2);');
Rmulv=-1;
Rst=['Change to r*R(r)';' Change to R(r) '];
Rmul=uicontrol('style','pushbutton',...
'string','Change to r*R(r)','position', [10 175 150 20],...
'callback',...
'Rmulv=-Rmulv;nold=-1;updaten;set(Rmul,''string'',Rst(fix(1.6+Rmulv/2),:));');
% Control of Paramter 'n'
%%%%%%%%%%%%%%%%%%%%%%%%%%
% Text field with value of 'n'
n_text = uicontrol('style','text', ...
'string','n=', 'position',[10 20 80 20]);
% Callback for n_slide (updates value of 'n' in the text-field
% and redraws the graph; it is contained in script file updaten.m
n_slide = uicontrol('style','slider', ...
'min',0,'max',10.0, ...
'position',[100 20 160 20], ...
'value',n, ...
'callback',['n=get(n_slide,''value'');updaten;']);
% Control of Paramter 'l'
%%%%%%%%%%%%%%%%%%%%%%%%%%
% Text field with value of 'l'
l_text = uicontrol('style','text', ...
'string','l=', 'position',[10 60 80 20]);
% Callback for n_slide (updates value of 'n' in the text-field
% and redraws the graph
% The actual slider control
l_slide = uicontrol('style','slider', ...
'min',0,'max',10.0, ...
'position',[100 60 160 20], ...
'value',l, ...
'callback',['l=get(l_slide,''value'');updatel;']);
% Parameter 'range'
%%%%%%%%%%%%%%%%%%%%
% Text field with value of 'range'
r_text = uicontrol('style','text', ...
'string','range=', 'position',[10 100 80 20]);
% Callback for r_slide (updates value of 'range' in the text-field
% and redraws the graph
%updater='eval(update_graph);set(r_text,''string'',[''range='' num2str(range)]);';
% The actual slider control
r_slide = uicontrol('style','slider', ...
'min',0,'max',200, ...
'position',[100 100 160 20], ...
'value',range, ...
'callback',['range=get(r_slide,''value'');updater;']);
% Parameter 'Evaluating...'
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following code does not work with some Matlab versions. If you have such
% problem try to use a different version of it.
figure(F1);
mess1=uicontrol('style','edit', ...
'string','Evaluating the symbolics ..........', ...
'BackgroundColor','red',...
'ForegroundColor','white',...
'position',[10 200 300 20], 'visible','off'); drawnow;
% Leaves the control window on top
figure(F2);

SUBROUTINES OF THE USER INTERFACE

UPDATER

% updater.m
% n is the integer such n>=1
if (n<0), n=1; end
% l is the integer such that 0<=l<n
l=fix(l); if (l<0), l=0; end; if (l>n-1), l=n-1; end;
figure(F2);
set(r_text,'string',[ 'range=' num2str(range)]); drawnow;
% Activate Drawing fingure
figure(F1);
% An array of numbers starting from 0 to range with step of range/100
% This array is used later on for graphs.
x=0:range/100:range;
if exist('com')==1
eval(com);
if Rmulv==-1
plot(x,y,[0 range], [0 0]);
else
plot(x,x.*y,[0 range], [0 0]);
end
end

Documentation

The program VISN visualize the wave function which is build in the program.
User is allowed to change interactively some parameters such as the value
sof corresponding quantum numbers and the range. Also it is possible to
switch between R(r) and r*R(r).

Subprograms

VISN

Main program of the user interface

UPDATER

Change the 'range' label text and replot the graph according to the
new range.

UPDATEN

UPDATEL

are used to update the sliders to show n and l values. And redraw the
graph according to the new values.

RADHYD

Calculate the normalized radial function as a string. (main function)

RADHYD0

The function radhyd0 is used internaly by radhyd.

NORMH

Calculate the inverse of the square of the normalization integral.

LAGGUERE

Calculate odd Lagguere polynomial.

DF

Calculate n-th derivative

Variables

n_slide, l_slide, r_slide

refer to the slider objects that decide the current values n, l, r.

Rmul

is the button object, which decides between plotting R(r) or r*R(r)

(in its call back routine is done the switching of the modes)

ExitBut

is the button object, which ends the program

n and l

Hold the values of corresponding quantum numbers of wave function in
hydrogen like atom.

range

Holds the current range.

expr

contains the character string which represents the current wavefunction

If the user is interested in the symbolic form of the wavefunction,
it can be obtained by typing

expr in the Matlab command window anywhere
during the execution of the program.

Instructions for the user

The programme is written in Matlab and can be used only from the Matlab
command. The user must have available the routines as listed above:

visn.m updatel.m updaten.m updater.m

radhyd.m df.m normh.m radhyd0.m lagguere.m

Running Matlab on any computer which has available the Symbolic Toolbox,
the user starts by typing

visn

Two windows appear, one is the control window, the other will later
show the wavefunction.

The mode of plotting is controled by the selfinstructing names of the
control elements.

The control window looks like this, before any action is applied

During the execution of the program:

If the user is interested in the symbolic form of the wavefunction,
it can be obtained by typing

expr

in the Matlab command window anywhere during the execution of the program.