function predator_ode45 ( )

%*****************************************************************************80
%
%% predator_ode45 computes and plots a solution to the predator problem.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    04 November 2020
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'predator_ode45' );
  fprintf ( 1, '  Solve predator-prey equation with ode45 method\n' );
  fprintf ( 1, '  Plot the solution.\n' );

  dydt = @predator_deriv;
  t0 = 0.0;
  tstop = 50.0;
  tspan = [ t0, tstop ];
  y0 = [ 4.0, 2.0 ];

  [ t, y ] = ode45 ( dydt, tspan, y0 );

  n = length ( t ) - 1;
  fprintf ( 1, '  Number of steps used N = %d\n', n );
 
  plot ( t, y(:,1), 'g-', t, y(:,2), 'r-', 'linewidth', 3 );
  grid ( 'on' ); 
  xlabel ( '<--T-->' );
  ylabel ( '<--R(T), F(T)-->' );
  s = sprintf ( 'predator ode45, time plot, n = %d.', n );
  title ( s );
  legend ( 'Rabbits', 'Foxes' );
  filename = 'predator_ode45.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 ode45, phase plot, n = %d.', n );
  title ( s );
  filename = 'predator_ode45_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 ode45, conservation plot, n = %d.', n );
  title ( s );
  filename = 'predator_ode45_conserved.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  fprintf ( 1, '  h(1) = %g, h(n+1) = %g\n', h(1), h(n+1) );

  return
end

