function func = stabdom ( imeth );
% StabDom
%
% This m-file is part of the material of the lecture
%   Scientific Computing and Software Tools
% at the Math Department of Halle University, Germany.
% Summer term 2004
%
% Author :      Prof. Dr. M. Arnold, arnold@mathematik.uni-halle.de
% Version of :  May 11, 2004
%
% Stability domain of discretization methods 
%
% Parameter
%   imeth  (input)  : control flag "method"
%                       = 1  ...  explicit RK
%                       = 2  ...  BDF
%
% Example
%   stabdom ( 1 );    %  print -dpng ../png/stabdom1.png
%   stabdom ( 2 );    %  print -dpng ../png/stabdom2.png

%
% -> Steuerparameter Ausgabe Bildschirm / PostScript
graphwidth  = 28.0;
graphheight = 15.0;
fac         =  0.95;
shift       =  0.5;
papershift  =  0.0;

ActFontSize   = 14;
ActMarkerSize =  6;
RatioFlag     =  0;

border      = 1.0;

%
% -> Bestimme Groesse des Bildschirms und Skalierungsfaktor fuer die Ausgabe
root = 0;
set ( root, 'Units', 'centimeters' );
screensize = get ( root, 'ScreenSize' );
left   = screensize(1);
bottom = screensize(2);
width  = screensize(3);
height = screensize(4);
set ( root, 'Units', 'pixels' );
if RatioFlag==0,
  screenscale = 1.0;
elseif RatioFlag==1,
  screenscale = (width-2*border) / graphwidth;
elseif RatioFlag==-1,
  screenscale = (height-2*border) / graphheight;
end;

%
% -> Definiere den Bildschirmausschnitt
if length ( get ( root, 'Children' ) ) == 0,
  h = figure;
else
  h = gcf;
  clf;
end;
stdunits = get ( h, 'Units' );
set ( h, 'Units',    'centimeters' );
set ( h, 'Position', ...
  [ left+width-border-screenscale*graphwidth height-2*border-screenscale*graphheight screenscale*graphwidth screenscale*graphheight ] );
set ( h, 'Units', stdunits );

%
% -> Skalierung der Ausgabe in PostScript
%
set ( gcf, 'PaperUnits',    'centimeters' );
set ( gcf, 'PaperPosition', [ papershift papershift graphwidth graphheight ] );

% -> plot dimensions
if imeth==1,
   points =  100;
   xmin   = -4;
   xmax   =  1.3;
   ymin   = -4.5;
   ymax   =  4.5;
   tstrl  = 'Explizites Eulerverfahren';
   tstrr  = 'Verfahren 5. Ordnung von Dormand/Prince';
elseif imeth==2,
   points =  1000;
   xmin   = -6;
   xmax   =  7;
   ymin   = -11;
   ymax   =  11;
   tstrl  = 'Implizites Eulerverfahren';
   tstrr  = 'BDF mit  p = k = 4';
end;
dyplot = (ymax-ymin)/75;

% -> plot
subplot ( 1, 2, 1 ); 
if imeth==1,                          
   markdom ( explrk(1, 1, points+1, 0),  1, xmin, xmax, ymin, ymax, dyplot, 0 );
elseif imeth==2,                          
   markdom ( bdf(1, 1, points+1),       -1, xmin, xmax, ymin, ymax, dyplot, 1 );
end;
plot ( [xmin xmax], [0 0], '-k' );                    
plot ( [0 0], [ymin ymax], '-k' );                  
hold off; 

axis ( [ xmin xmax ymin ymax ] ); 
set (gca, 'DataAspectRatio', [ 1 1 1 ] );                    
title ( tstrl );  
xlabel ( 'Re z' );
ylabel ( 'Im z' ); 

subplot ( 1, 2, 2 );                           
if imeth==1,                          
   markdom ( explrk(2, 4, points+1, 0),      1, xmin, xmax, ymin, ymax, dyplot, 0 );
   markdom ( explrk(2, 1, points+1, 1+4*i),  1, xmin, xmax, ymin, ymax, dyplot, 0 );
   markdom ( explrk(2, 1, points+1, 1-4*i),  1, xmin, xmax, ymin, ymax, dyplot, 0 );
elseif imeth==2,                          
   markdom ( bdf(4, 1, points+1),           -1, xmin, xmax, ymin, ymax, dyplot, 1);
end;
plot ( [xmin xmax], [0 0], '-k' );                    
plot ( [0 0], [ymin ymax], '-k' );                  
hold off;

axis ( [ xmin xmax ymin ymax ] );                     
set (gca, 'DataAspectRatio', [ 1 1 1 ] );                    
title ( tstrr );   
xlabel ( 'Re z' );
ylabel ( 'Im z' ); 

%
% -> Korrektur der Groesse und Lage der Koordinatensysteme, Aenderung der Schriftgroesse
allax = get ( gcf, 'Children' )';
for ax = allax,
  rect    = get ( ax, 'Position' );
  rect(2) = rect(2) + shift * (1-fac) * rect(4);
  rect(4) = fac * rect(4);
  set ( ax, 'Position', rect );
  set ( ax, 'FontSize', [ActFontSize] );
  set ( get ( ax, 'title' ), 'FontSize', [ActFontSize] );
  set ( get ( ax, 'xlabel' ), 'FontSize', [ActFontSize] );
  set ( get ( ax, 'ylabel' ), 'FontSize', [ActFontSize] );
  allline = get ( ax, 'Children' )';
  for al=allline,
    if get ( al, 'Type' ) == 'line',
      set ( al, 'MarkerSize', [ ActMarkerSize ] );
    end;
  end;
end;
