function func = lindglrl ( iinput );
% LinDglRL
%
% This m-file is part of the material of the lecture
%   Theory and Numerics of Ordinary Differential Equations
% at the Math Department of Halle University, Germany.
% Winter term 2004/05
%
% Author :      Prof. Dr. M. Arnold, arnold@mathematik.uni-halle.de
% Version of :  Oct 18, 2004
%
% Linear Differential equation, Example: RL circuit
%
% Reference
%   Meyberg, Vachenauer (II), Kapitel 9, §2, Beispiel 5
%
% Parameter:
%   iinput (input)  : control flag "input"
%                       =1 .. U(t) constant 
%                       =2 .. U(t) oscillating
%
% Examples:
%   lindglrl ( 1 );   %   print -dpng ../png/lindglrl1.png
%   lindglrl ( 2 );   %   print -dpng ../png/lindglrl2.png

graphwidth  = 14.0;
graphheight = 12.0;
vfac        =  0.95;
vshift      =  0.4;
hfac        =  0.99;
hshift      =  2.0;
papershift  =  0.0;

ActFontSize   = 14;
ActLineWidth  =  2;
ActMarkerSize = 12;
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;
end;

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

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

% -> physical parameters
R  = 1.0e03;
L  = 8.0;
U0 = 220.0;
omega = 2*pi*50.0;

if iinput==1,
    tmin = 0.0;
    tmax = 0.05;
    Imin = 0.0;
    Imax = 2*U0 / R;
    tstr = sprintf ( 'Gleichspannung  U(t) = %3.0f [V]', U0 );
elseif iinput==2,
    tmin = -0.005;
    tmax =  0.02;
    Imin = -0.5*U0 / R;;
    Imax =  1.0*U0 / R;;
    tstr1 = sprintf ( 'Wechselspannung  U(t) = %3.0f*cos(2*', U0 );
    tstr2 = sprintf ( '*%2.0ft)  [V]', omega/(2*pi) );
    tstr  = [ tstr1 '\pi' tstr2 ];
end;

tt   = linspace ( tmin, tmax, 201 );

if iinput==1,
    plot ( [ tmin tmax ], U0/R*[ 1 1 ], '-r', 'LineWidth', 2 );
    hold on;
    for scal=0.3:0.2:1.9,
        I0 = scal * U0/R;
        plot ( tt, U0/R-(U0/R-I0)*exp(-R/L*tt), 'b', 'LineWidth', 1 );
    end;
    plot ( [ tmin tmax ], U0/R*[ 1 1 ], '-r', 'LineWidth', 2 );
    hold off;
elseif iinput==2,
    delta = atan ( omega*L / R );
    ILim  = U0 / sqrt(R^2+omega^2*L^2) * cos(omega*tt-delta);
    plot ( [ tmin tmax ], [ 0 0 ], ':k' );
    hold on;
    plot ( [ 0 0 ], [ Imin Imax ], ':k' );
    for scal=-0.02:0.02:0.12,
        I0 = scal * U0/R;
        plot ( tt, ILim+scal*exp(-R/L*tt), 'b', 'LineWidth', 1 );
    end;
    plot ( tt, ILim, 'r', 'LineWidth', 3 );
    hold off;
end;

axis ( [ tmin tmax Imin Imax ] );

xlabel ( 't' );
ylabel ( 'I' );
title ( tstr );

%
% -> Korrektur der Groesse und Lage der Koordinatensysteme
allax = get ( gcf, 'Children' )';
for ax = allax,
  rect    = get ( ax, 'Position' );
  rect(1) = rect(1) + hshift * (1-hfac) * rect(3);
  rect(3) = hfac * rect(3);
  rect(2) = rect(2) + vshift * (1-vfac) * rect(4);
  rect(4) = vfac * rect(4);
  set ( ax, 'Position', rect );
end;

%
% -> Aenderung der Schriftgroesse etc.
for hf = allax,
  set ( hf, 'FontSize', [ActFontSize] );
  set ( get ( hf, 'title' ), 'FontSize', [ActFontSize] );
  set ( get ( hf, 'xlabel' ), 'FontSize', [ActFontSize] );
  set ( get ( hf, 'ylabel' ), 'FontSize', [ActFontSize] );
  allch = get ( hf, 'Children' )';
  for hch = allch,
    if strcmp(get(hch,'Type'),'line'),
      % set ( hch, 'LineWidth',  ActLineWidth );
      set ( hch, 'MarkerSize', ActMarkerSize );
    end;
  end;
end;

