function predator_rk1 ( n )

%*****************************************************************************80
%
%% predator_rk1 use rk1 (euler) on the predator problem.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    19 September 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N: the number of steps to take.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'predator_rk1' );
  fprintf ( 1, '  Solve predator-prey equation with the rk1 method\n' );
  fprintf ( 1, '  Plot the solution, phase plane, conservation.\n' );

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

  dydt = @predator_deriv;
  tspan = [ 0.0, 50.0 ];
  u0 = 4.0;
  v0 = 2.0;
  y0 = [ u0; v0 ];
  [ t, y ] = rk1 ( dydt, tspan, y0, n );

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

  figure ( 2 )
  plot ( y(:,1), y(:,2), 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( '<-- R(T)-->' );
  ylabel ( '<-- F(T)-->' );
  s = sprintf ( 'Predator ODE rk1, n = %d.', n );
  title ( s );
  filename = sprintf ( 'predator_rk1_phase_%d.png', n );
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Conservation.
%
  alpha = 2.0;
  beta = 1.0;
  gamma = 1.0;
  delta = 1.0;

  u = y(:,1);
  v = y(:,2);
  c0 = delta * u0 - gamma * log ( u0 ) + beta * v0 - alpha * log ( v0 );
  c =  delta * u  - gamma * log ( u )  + beta * v  - alpha * log ( v );
  figure ( 3 )
  plot ( t, c, 'r-', ...
         [t(1),t(end)], [c0,c0], 'b--', ...
         [t(1),t(end)], [0,0], 'k-', 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( '<-- T -->' );
  ylabel ( '<-- C(T) -->' );
  s = sprintf ( 'Predator ODE, rk1: C(T) should be constant, N = %d.', n );
  title ( s );
  filename = sprintf ( 'predator_rk1_conservation_%d.png', n );
  print ( '-dpng', filename );

  return
end

