function predator_prey_rk4 ( n )

%*****************************************************************************80
%
%% predator_prey_rk4() applies n steps of an ode solver to the predator problem.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 April 2021
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer n: the number of steps.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'predator_prey_rk4():\n' );
  fprintf ( 1, '  Use rk4() to solve the predator-prey ODE.\n' );

  [ alpha, beta, gamma, delta, t0, y0, tstop ] = predator_prey_parameters ( );

  f = @predator_prey_deriv;
  tspan = [ t0, tstop ];

  [ t, y ] = rk4 ( f, tspan, y0, n );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of equal steps = %d\n', n );

  figure ( 1 );
  clf ( );
  plot ( t, y, 'linewidth', 3 );
  grid ( 'on' );
  legend ( 'Rabbits', 'Foxes' );
  title ( 'Predator Prey rk4 plot' );
  filename = 'predator_prey_rk4_plot.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  
  figure ( 2 );
  clf ( );
  plot ( y(:,1), y(:,2), 'linewidth', 3 );
  grid ( 'on' );
  title ( 'Predator Prey rk4 phase' );
  filename = 'predator_prey_rk4_phase.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  h = predator_prey_conserved ( y );

  figure ( 3 );
  clf ( );
  hold ( 'on' )
    plot ( t, h, 'r-', 'linewidth', 3 );
    plot ( tspan, [h(1), h(1)], 'b--', 'linewidth', 3 );
    plot ( tspan, [0.0,0.0], 'k--' );
  hold ( 'off' );
  grid ( 'on' );
  title ( 'Predator Prey rk4 conservation ' );
  filename = 'predator_prey_rk4_conservation.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

