function predator_rk2 ( n )

%*****************************************************************************80
%
%% predator_rk2 computes and plots a solution to the predator problem.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    02 November 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N: the number of steps to take.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'predator_rk2' );
  fprintf ( 1, '  Solve predator-prey equation with rk2 method\n' );
  fprintf ( 1, '  Plot the solution.\n' );

  if ( nargin < 1 )
    n = 100;
    fprintf ( 1, '\n' );
    fprintf ( 1, '  Input value N not supplied.  Using N = %d\n', n );
  end

  dydt = @predator_deriv;
  t0 = 0.0;
  tstop = 50.0;
  tspan = [ t0, tstop ];
  y0 = [ 4.0, 2.0 ];
  [ t, y ] = rk2 ( dydt, tspan, y0, n );

  plot ( t, y(:,1), 'g-', t, y(:,2), 'r-', 'linewidth', 3 );
  grid ( 'on' ); 
  xlabel ( '<--T-->' );
  ylabel ( '<--R(T), F(T)-->' );
  s = sprintf ( 'predator rk2, time plot, n = %d.', n );
  title ( s );
  legend ( 'Rabbits', 'Foxes' );
  filename = 'predator_rk2.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  figure ( 2 );
  clf ( );
  plot ( y(:,1), y(:,2), 'linewidth', 2 );
  grid ( 'on' );
  xlabel ( 'Rabbits' );
  ylabel ( 'Foxes' );
  s = sprintf ( 'predator rk2, phase plot, n = %d.', n );
  title ( s );
  filename = 'predator_rk2_phase.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  h = predator_conserved ( y );
  figure ( 3 );
  clf ( );
  hold ( 'on' );
  plot ( t, h, 'r-', 'linewidth', 3 );
  plot ( [ t0, tstop ], [0.0, 0.0], 'k-', 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- T -->', 'Fontsize', 16 );
  ylabel ( '<-- H(T) -->', 'Fontsize', 16 );
  s = sprintf ( 'predator rk2, conservation plot, n = %d.', n );
  title ( s );
  filename = 'predator_rk2_conserved.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

