function func = plotwave ( c );
% PlotWave
%
% This m-file is part of the material of the lecture
%   Theory and Numerics of Partial Differential Equations
% at the Math Department of Halle University, Germany.
%
% Author :      Prof. Dr. M. Arnold, arnold@mathematik.uni-halle.de
% Version of :  Apr 7, 2005
%
% Animated Plot of the solution of the Wave equation
%
% Parameters:
%   c      (input)  : wave speed
%
% Example:
%   plotwave ( 2.5 );   % print -dpng ../png/plotwave.png
%   plotwave ( 1.5 );
%   plotwave ( 3.5 );

graphwidth  = 16.0;
graphheight = 12.0;
fac         =  0.95;
shift       =  0.5;
papershift  =  0.0;

ActFontSize   = 14;
ActLineWidth  =  2;
ActMarkerSize =  8;
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 ] );

% -> data grid
nx = 201;
nt = 101;

xmin = -5.0;
xmax =  5.0;
tmin =  0.0;
tmax =  1.0;

x = linspace ( xmin, xmax, nx );
t = linspace ( tmin, tmax, nt );

[ X, T ] = meshgrid ( x, t );

% -> solution of wave equation
U = exp(-(X+c*T).^2/2) + exp(-(X-c*T).^2/2);

% -> first plot
mymesh = mesh ( X, T, U );
view ( -162, 35 );
xlabel ( 'x' );
ylabel ( 't' );
zlabel ( 'u' );

drawnow;

%
% -> Korrektur der Groesse und Lage der Koordinatensysteme
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 );
end;

%
% -> Aenderung der Schriftgroesse
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] );
  set ( get ( hf, 'zlabel' ), 'FontSize', [ActFontSize] );
end;

% -> animation
for iplot=3:nt,
    Uact = U;
    Uact(iplot:end,:) = NaN;
    set ( mymesh, 'ZData', Uact );
    drawnow;
end;

