function func = solivp;
% SolIVP
%
% 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 2006/07
%
% Author :      Prof. Dr. M. Arnold, martin.arnold@mathematik.uni-halle.de
% Version of :  Nov 10, 2006
%
% Illustration of locally unique Solvability of Initial Value Problems
%
% Reference
%   von Finckenstein et al. II, Section 3, Example (5b)
%
% Parameter:
%   none
%
% Example:
%   solivp;   %   print -dpng ../png/solivp.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 ] );

% -> plot data
xmin = -4.0;
xmax =  3.0;
ymin = -2.0;
ymax =  4.0;

x0 = 0.0;
y0 = 2.0;

xx = linspace ( xmin, xmax, 10001 );

h = fill ( [ -1.2 1.2 1.2 -1.2 ], [ 1 1 3 3 ], [ 1 0.9 0.9 ]    ...
         , 'EdgeColor', 'r'                             ...
         , 'LineWidth', ActLineWidth                    ...
         );
hold on;

plot ( [ xmin xmax ], [ 0 0 ], '-k' );
plot ( [ 0 0 ], [ ymin ymax ], '-k' );

yy1 = zeros ( size ( xx ) );
yy1(xx<-2.5)     = (xx(xx<-2.5)     + 2.5    ).^3;
yy1(xx>-2^(1/3)) = (xx(xx>-2^(1/3)) + 2^(1/3)).^3;
h1 = plot ( xx, yy1, '-g', 'LineWidth', ActLineWidth );

yy2 = (xx+2^(1/3)).^3;
hwin = 0.25;   y = -0.5 * hwin;
while (y<ymax),
    y = y + hwin;
    yy2((yy2>=y)&(yy2<(y+hwin))) = NaN;
    y = y + hwin;
end;
h2 = plot ( xx, yy2, '-b', 'LineWidth', ActLineWidth );

plot ( x0, y0, 'om', 'MarkerSize', ActMarkerSize-1 );
plot ( x0, y0, 'om', 'MarkerSize', ActMarkerSize );
plot ( x0, y0, 'xm', 'MarkerSize', ActMarkerSize );

text ( -0.8, 2.5, 'R', 'Color', 'r', 'FontSize', 20 );

hold off;

set ( gca, 'DataAspectRatio',    [ 1 1 1 ] );

axis ( [ xmin xmax ymin ymax ] );

xlabel ( 'x' );
ylabel ( 'y' );
title ( 'Lokale Eindeutigkeit der Loesung' );

%
% -> 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;

% -> Legende
legend ( [ h2 h1 ]               ...
       , ' c = 2^{1/3}'          ...
       , ' c = 2.5'              ...
       , 'Location', 'NorthWest' ...
       );
