%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is the Matlab 5 version
% golden5.m solves the diff. equations for the Fermi golden5 Rule
% Made by Atomic Physics, Bergen, L. Kocbach Okt 20.-Nov 15. 1996
% This version is contained in one m-file. Other versions exist.
%
% There is a quite extensive help inside. To start, press the
% > CALC button. The slider can be used to move in time.
%
% > Problem: golden5 will not start, nothing happens.
% Solution: enter the command: clear all
% This occurs when you crashed golden5 or in similar
% situations.
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ( ~exist('golden5RuleFl') )
golden5RuleFl=0;
end;
if golden5RuleFl==0
if exist('HelpfigNumber')
if HelpfigNumber~=3335, delete(HelpfigNumber);end;
end;
clear A To0 pp2 Bstop V0 pp3 Cdone axHndl runner
clear E0 calling s1 EnerBut count s2 ...
GOLDCALC defolt s3 GOLDCONT deltaE s4 GOLDHELP energ t ...
GOLDINIT frmPos t0 GTf from0 tfinal GTfL gV0 titleStr ...
GTs gnnn tocalc GTsL gtfin todestroy GUIbuild gth tout ...
GVi h uu GViL helpStr1 vect Gnn helpStr2 vv ...
GnnL helpStr3 vvv GoMore helpStr4 xpos
clear HelpfigNumber hlp xx ...
OnWhat k youtPausing kgt yp ReDo kk ypos STf kmax yv ...
STs matr yy SVi nn zzz SlidK nnn Snn onestep TextStrs pp1
golden5RuleFl=1;
GOLDINIT=1; GOLDCALC=2; GOLDCONT=3; GOLDHELP=4;GUIbuild=6;
calling=0;
todestroy=0;onestep=0; from0=0; runner=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Cdone=0;
%
% Based on the Expo help function
%
HelpfigNumber=3335;
TextStrs=[ 'About'
'Using'
'Use 2'
'Hints'];
helpStr1= ...
[' The Golden Rule Simulator solves '
' time-dependent Schrodinger equation'
' '
' The hamiltonian matrix has a form '
' '
' [ E V V V V V V V '
' V -n 0 0 0 0 0 0 '
' V 0 -n+1 0 0 0 0 0 '
' V 0 0 -n+2 0 0 0 0 '
' V 0 0 0 E 0 0 0 '
' V 0 0 0 0 n-2 0 0 '
' V 0 0 0 0 0 n-1 0 '
' V 0 0 0 0 0 0 n ] '
' '
' -----------------------------------'
' '
' The purpose is to show how the '
' probability flows to quasicontinuum'];
helpStr2= ...
[' TO START: PRESS the Button CALC !! '
' When started, it solves the TDSE. '
' After the solution is finished, it '
' repeats showing the solution. '
' 1. Stop button during the solution '
' stops the solution at the given '
' time. It immediately shows it, '
' i.e. there is still motion. '
' 2. Stop button during showing phase'
' stops the animation at a given t'
' It can be made to move pressing '
' same button, now named . '
' 3. The button <1 step> moves the '
' animation by 1 step only. '
' 4. Button moves the animation'
' at the start. If during calc., '
' works as stop; Animation is set '
' to t=0. If no motion, one step. '];
helpStr3= ...
[' 5. Popul(ation) shows the amplitude'
' squared of the static solution '
' 6. CALC(ulate): use the current '
' parameters and repeat the calc. '
' or start the first time!!! '
' 7. tmax= shows the value used til '
' now. To set a new value, enter '
' it in the editable field and'
' hit Return '
' 8. dt= and dt as in 7. '
' 9. Vint= and Vi, as 7. '
' 10. Std.Val sets all values to the '
' initial ones. '
' 11. The slider stops animation and '
' moves it to the selected time. '
' 12. The vertical slider (right) '
' changes the scale of population '
' display. '
'-------------------------------------'
' '];
helpStr4= ...
['Hints: '
' Try to run with small values of nn '
' It will show that you do not get '
' smooth decay if the number is not '
' large enough. '
' '
' Try to run with large number of nn '
' Then the energy range gets wider '
' '
' Try to run with tm large (above 150)'
' You will observe reccurrence! '
' It is very nice with very large tm '
' You can reduce computation if dt~0.5'
'-------------------------------------'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Model parameters
%
V0=0.08; %% strength of the coupling
E0=1; %% The discrete state energy
deltaE=0.05; %% Spacing between the quasicontinuum
h=0.2; %% Time step
t0=0; %% Time origin
tfinal=10; %% Time end
nn=30; %% Number of states parameter
nnn=2*nn+2; %% Total number of states
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
gV0=V0; gnnn=nn; gtfin=tfinal; gth=h;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
calling=GOLDINIT; golden5;
calling=GUIbuild; golden5;
else
%
%
%
if todestroy==1, golden5RuleFl=0; end;
if calling==GUIbuild
%%%%%% GRAPHICS and GUI %%%%%%
axHndl=figure( 'position',[16 64 1008 420], ...
'Name', 'Fermi golden5 Rule Simulator ' , ...
'NumberTitle','off');
set(axHndl,'Interruptible','on');
runner=0;
%
frmPos=[0 0 66 410];
vvv=uicontrol( ...
'Style','frame', ...
'Units','pixels', ...
'Position',frmPos, ...
'BackgroundColor',[0.5 0.1 0.2]);
%
% Finish the Program, close all windows
%
Bstop = uicontrol('style','push','string','close',...
'position',[3 5 60 20], ...
'callback', [ 'if runner==0,delete(gcf),else,'...
'todestroy=1; fdestroy=gcf; runner=0;golden5RuleFl=0;' ...
'if(HelpfigNumber~=3335), delete(HelpfigNumber);end;' ...
' HelpfigNumber=3335; end; golden5RuleFl=0;' ],...
'Interruptible','on');
%
% Go to t=0
%
To0 = uicontrol('style','push','string','t=0 ',...
'position',[3 105 60 20], ...
'callback', [' if (Cdone==1)&tocalc==1,runner=0; tocalc=0; kmax=k-1; else'...
' from0=1; '...
' if (Cdone==1)&runner==0, onestep=1;'...
' calling=GOLDCONT; golden5; end; end;'] ,...
'Interruptible','on');
tocalc=1;
%
% Stop animation or stop calculation
%
Pausing = uicontrol('style','push','string','stop ',...
'position',[3 30 60 20], ...
'callback',...
[ ' if runner==1 & tocalc==1, runner=0; tocalc=0; else ' ...
' if runner==1 & tocalc==0, set(Pausing,''string'',''cont''); '...
'runner=0; tocalc=0; else set(Pausing,''string'',''stop''); ' ...
' if (Cdone==1)&(runner==0)&(todestroy==0)&(tocalc==0),'...
'runner=1; calling=GOLDCONT; golden5; end; '...
'end; end; '] ,...
'Interruptible','on');
tocalc=1;
%
% Continue animation
%
GoMore = uicontrol('style','push','string',' 1 step ',...
'position',[3 55 60 20], ...
'callback', [' if (Cdone==1)&(runner==0)&(todestroy==0)&(tocalc==0),'...
' onestep=1; calling=GOLDCONT; golden5; end; ' ],...
'Interruptible','on');
%
% help
%
titleStr='golden5 Rule Simulator';OnWhat='golden5 Rule';
hlp= uicontrol('Style','push','Position',...
[3 80 60 20],...
'Callback',...
'calling=GOLDHELP; golden5; ',...
'String',' Help ');
%
% Plot Eigenenergies
%
EnerBut=uicontrol('style','push','string','Popul.',...
'position',[3 130 60 20], ...
'callback', [ 'if Cdone==1,figure(axHndl); subplot(2,1,1);' ...
'plot(xpos,ypos,''o''); end'],...
'Interruptible','on');
%
% Do the Calculation
%
ReDo=uicontrol('style','push','string',' CALC ',...
'position',[3 155 60 20], ...
'callback', [ 'if runner==0,tocalc=1; runner=1; nn=10; '...
'set(Pausing,''string'',''stop'');' ...
'calling=GOLDINIT; golden5; ' ...
' figure(axHndl); subplot(2,1,1);cla;subplot(2,1,2);cla;'...
'calling=GOLDCALC; golden5; end'],...
'Interruptible','on');
%
% Tfinal
%
STf=uicontrol('Style','text',...
'Position',[3 205 60 20],'String',['tmax=' num2str(tfinal)]);
set(STf,'String',['tm=' num2str(tfinal)]);
GTfL=uicontrol('Style','text',...
'Position',[3 180 25 20],'String',['tm']);
GTf= uicontrol('Style','edit','Position',...
[28 180 35 20],...
'Callback',['gtfin=str2num(get(GTf,''String''));'...
'set(GTf,''String'',num2str(gtfin));' ...
'set(STf,''String'', [''tmax='' num2str(gtfin)] );' ],...
'String',' '); %% init: tfinal=gtfin;
%
% h: tstep
%
STs=uicontrol('Style','text',...
'Position',[3 255 60 20],'String',['d t=' num2str(h)]);
set(STs,'String',['dt=' num2str(h)]);
GTsL=uicontrol('Style','text',...
'Position',[3 230 25 20],'String',['dt']);
GTs= uicontrol('Style','edit','Position',...
[28 230 35 20],...
'Callback',['gth=str2num(get(GTs,''String''));'...
'set(GTs,''String'',num2str(gth));'...
'set(STs,''String'',[''d t='' num2str(gth)]);'],...
'String',' '); %% init: h=gth;
%
% Vint interaction strength
%
SVi=uicontrol('Style','text',...
'Position',[3 305 60 20],'String',['Vi=' num2str(V0)]);
set(SVi,'String',['Vint=' num2str(V0)]);
GViL=uicontrol('Style','text',...
'Position',[3 280 25 20],'String',['Vi' ]);
GVi= uicontrol('Style','edit','Position',...
[28 280 35 20],...
'Callback',['gV0=str2num(get(GVi,''String''));' ...
'set(GVi,''String'',num2str(gV0));' ...
'set(SVi,''String'',[''Vi='' num2str(gV0)]);' ], ...
'String',' '); %% init: V0=gV0;
%
% n/2 number of states
%
Snn=uicontrol('Style','text',...
'Position',[3 355 60 20],'String',['nn=' num2str(nn)]);
set(Snn,'String',['n1/2=' num2str(nn)]);
GnnL=uicontrol('Style','text',...
'Position',[3 330 25 20],'String',['nn' ]);
Gnn= uicontrol('Style','edit','Position',...
[28 330 35 20],...
'Callback',['gnnn=str2num(get(Gnn,''String''));'...
'set(Gnn,''String'',num2str(gnnn));' ...
'set(Snn,''String'',[''nn='' num2str(gnnn)]); '], ...
'String',' '); %% init: nn=gnnn;
defolt=uicontrol('style','push','string','Std.Val',...
'position',[3 380 60 20], ...
'callback', [ 'gV0=0.08; gnnn=30; gtfin=10; gth=0.2;'...
'set(Snn,''String'',[''nn='' num2str(gnnn)]);'...
'set(SVi,''String'',[''Vi='' num2str(gV0)]);' ...
'set(STs,''String'',[''d t='' num2str(gth)]);' ...
'set(STf,''String'', [''tmax='' num2str(gtfin)] );' ...
'set(Gnn,''String'', num2str(gnnn));'...
'set(GVi,''String'', num2str(gV0));' ...
'set(GTs,''String'', num2str(gth));' ...
'set(GTf,''String'', num2str(gtfin));' ],...
'Interruptible','on');
HeighTxt=uicontrol('Style','text','Units','normalized',...
'Position',[0.92 0.43 0.06 0.05],'String',num2str(konst));
set(HeighTxt,'String', num2str(konst));
HeigSli = uicontrol('style','slider',...
'min',1,'max',gnnn*0.8,...
'Units','normalized', ...
'value',konst, ...
'position',[0.94,0.5,0.02,0.45],...
'callback',[ ' konst=get(HeigSli,''value'');'...
' set(HeighTxt,''String'', num2str(konst));' ...
' ypos=konst*vect(1,:).*vect(1,:);']);
SlidK=uicontrol('style','slider');
set(SlidK,'min',0,'max',0.01,...
'Units','normalized', ...
'position',[0.1,0.005,0.85,0.03],...
'callback',...
['runner=0;if Cdone==1 , kgt=get(SlidK,''value''); kgt=floor(kgt);'...
'if(kgt2)
set(pp2,'Xdata',tout(1:k),'Ydata',yout(1,1:k));
drawnow
set(pp3,'Xdata',[ tout(1) tout(k)]);
drawnow
end
%%% Plotting step finished
if todestroy==1
delete(fdestroy); runner=0;
if(HelpfigNumber~=3335) delete(HelpfigNumber);
end;
HelpfigNumber=3335;golden5RuleFl=0;
end;
end % while
runner=1; tocalc=0; Cdone=1;
%%
%% Repeated animations
%%
kmax=k;
if todestroy==0
set(SlidK,'min',0,'max',kmax-2)
set(SlidK,'Units','normalized', ...
'position',[0.1 0.005 0.85*kmax/(tfinal/h) 0.03])
end;
t=t0;k=0;
if(todestroy==0)
calling=GOLDCONT; golden5;
if(HelpfigNumber~=3335) delete(HelpfigNumber);
end;
HelpfigNumber=3335;
end;
if todestroy==1, golden5RuleFl=0; end;
%%%
%%%
end; %%%%% end goldcalc part
%%%
%%%
if calling==GOLDCONT
while (runner==1 | onestep==1 ) % if not stopped
runner=runner;
if k>kmax-1,k=0;end;
if(from0==1) k=0;from0=0; end;
k = k+1;
% Start plotting
if(k==1 & ( onestep==1 | runner==1 ) )
figure(axHndl);
subplot(2,1,1);hold off;
xx=9:nnn+8; xx(1)=3;
xx=[xx;xx;xx];xx=reshape(xx,3*nnn,1);
yp=yout(:,k);
yp(2:nnn)=konst*yp(2:nnn);
yv=[vv;yp';vv];yv=reshape(yv,3*nnn,1);
pp1= plot(xx,yv,'-');hold on;
set(pp1,'erase','background');
else
if( runner==1 | onestep==1 )
yp=yout(:,k);
yp(2:nnn)=konst*yp(2:nnn);
yv=[vv;yp';vv];yv=reshape(yv,3*nnn,1);
set(pp1,'Ydata', yv );
end;
end
drawnow
if(k==2 | onestep==1 )
figure(axHndl);
subplot(2,1,2);
set(pp3,'erase','normal')
set(pp3,'Xdata',tout(1:2));
set(pp3,'erase','none');
set(pp2,'erase','normal')
set(pp2,'Xdata',tout(1:k),'Ydata',yout(1,1:k));
set(pp2,'erase','none');
end
% Continue plotting
if(k>2)
set(pp2,'Xdata',tout(1:k),'Ydata',yout(1,1:k));
set(pp3,'Xdata',[ tout(1) tout(k)]);
drawnow
end;
onestep=0; from0=0; %% for the t=0 function
if todestroy==1, delete(fdestroy); runner=0;
if(HelpfigNumber~=3335) delete(HelpfigNumber);
end; HelpfigNumber=3335;golden5RuleFl=0;
end;
end % while k
%%% if( singlestep==1, onestep=0; end;
end % if not stopped
%%%
%%%
end; %%%%% end goldcont part
%%%
%%%
if calling == GOLDHELP
% HELPFN1 Utility function for displaying help text conveniently.
% Modified by L. Kocbach, Nov. 1996
% modified to work also on student edition, removed gco
% Modification: removing the specific Expomap calls
% Adding a string to change the title
% titleStr,OnWhat,helpStr1,helpStr2,helpStr3
% Based on HELPFUN Utility function
% Ned Gulley, 6-21-93
% Copyright (c) 1984-94 by The MathWorks, Inc.
%
numPages=4;
% If the Help Window has already been created, bring it to the front
newHelpWindowFlag=HelpfigNumber==3335;
figNumber=HelpfigNumber;
if newHelpWindowFlag,
position=[50 30 520 440];
HelpfigNumber=figure( ...
'Name',['MATLAB Info Window on ' OnWhat ], ...
'NumberTitle','off', ...
'NextPlot','new', ...
'Visible','off', ...
'Position',position, ...
'Colormap',[]);
figNumber=HelpfigNumber;
%===================================
% Set up the Help Window
top=0.95;
left=0.05;
right=0.75;
bottom=0.05;
labelHt=0.05;
spacing=0.005;
% First, the Text Window frame
frmBorder=0.02;
frmPos=[left-frmBorder bottom-frmBorder ...
(right-left)+2*frmBorder (top-bottom)+2*frmBorder];
uicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position',frmPos, ...
'BackgroundColor',[0.5 0.5 0.5]);
% Then the text label
labelPos=[left top-labelHt (right-left) labelHt];
ttlHndl=uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',[0.5 0.5 0.5], ...
'ForegroundColor',[1 1 1], ...
'String',titleStr);
% Then the editable text field (of which there are three)
% Store the text field's handle two places: once in the figure
% UserData and once in the button's UserData.
for count=1:4,
helpStr=eval(['helpStr',num2str(count)]);
txtPos=[left bottom (right-left) top-bottom-labelHt-spacing];
txtHndlList(count)=uicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Max',20, ...
'String',helpStr, ...
'BackgroundColor',[1 1 1], ...
'Visible','off', ...
'Position',txtPos);
end;
set(txtHndlList(1),'Visible','on');
%====================================
% Information for all buttons
labelColor=[0.8 0.8 0.8];
top=0.95;
bottom=0.05;
yInitPos=0.80;
left=0.80;
btnWid=0.15;
btnHt=0.10;
% Spacing between the button and the next command's label
spacing=0.05;
%====================================
% The CONSOLE frame
frmBorder=0.02;
yPos=bottom-frmBorder;
frmPos=[left-frmBorder yPos btnWid+2*frmBorder 0.9+2*frmBorder];
uicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position',frmPos, ...
'BackgroundColor',[0.5 0.5 0.5]);
%====================================
% All required BUTTONS
for count=1:4
% The PAGE button
labelStr=TextStrs(count,:);
% The callback will turn off ALL text fields and then turn on
% only the one referred to by the button.
callbackStr= ...
['txtHndl=txtHndlList(' num2str(count) ');' ...
'hndlList=get(gcf,''UserData'');' ...
'set(hndlList(2:5),''Visible'',''off'');' ...
'set(txtHndl,''Visible'',''on'');'];
btnHndlList(count)=uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[left top-btnHt-(count-1)*(btnHt+spacing) btnWid btnHt], ...
'String',labelStr, ...
'UserData',txtHndlList(count), ...
'Visible','off', ...
'Callback',callbackStr);
end;
%====================================
% The CLOSE button
callbackStr= ...
'delete(gcf); HelpfigNumber=3335;';
uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[left 0.05 btnWid 0.10], ...
'String','Close', ...
'Callback',callbackStr);
hndlList=[ttlHndl txtHndlList btnHndlList];
set(figNumber,'UserData',hndlList)
else
figure(HelpfigNumber);
end;
% Now that we've determined the figure number, we can install the
% Desired strings.
hndlList=get(figNumber,'UserData');
ttlHndl=hndlList(1);
txtHndlList=hndlList(2:5);
btnHndlList=hndlList(6:9);
set(ttlHndl,'String',titleStr);
set(txtHndlList(2:4),'Visible','off');
set(txtHndlList(1),'Visible','on');
set(txtHndlList(1),'String',helpStr1);
set(txtHndlList(2),'String',helpStr2);
set(txtHndlList(3),'String',helpStr3);
set(txtHndlList(4),'String',helpStr4);
set(btnHndlList(1:numPages),'Visible','on');
set(HelpfigNumber,'Visible','on');
%%%
%%%
end; %%%%% end goldhelp part
%%%
%%%
if todestroy==1, golden5RuleFl=0; end;
%% end; %% of the whole else ...