function lotka_test ( )

%*****************************************************************************80
%
%% lotka()_test applies continuation to the Lotka problem.
%
%  Discussion:
%
%    For the Lotka Volterra equations:
%
%      du/dt = u * ( v - 2 )
%      dv/dt = v * ( 1 - u )
%
%    the Hamiltonian is:
%
%      H(u,v) = u - log ( u ) + v - 2 * log ( v )
%
%    Given a starting value (4,2), our function f(x,y) is 
%      f(x,y) = H(x,y) - H(4,2)
%    or:
%      f(x,y) = x - log(x) + y - 2 * log(y) - 6 + log(16)
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 September 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'lotka_test():\n' );
  fprintf ( 1, '  Trace points on the Hamiltonian curve associated\n' );
  fprintf ( 1, '  with a Lotka problem.\n' );

  step_max = 200;
  step_num = 0;
  xy = zeros ( 2, step_max );
%
%  A: 
%  Choose a starting point,
%  Choose a starting "parameter",
%  Call Newton to try to get starting point to satisfy implicit function
%  while holding parameter fixed.
%
  n = 2;
  x0 = [ 4.0; 2.0 ];
  p0 = 2;
  tol = 1.0E-05;

  fx_norm = max ( abs ( f_lotka ( n, x0 ) ) );
  fprintf ( 1, '  %2d  %14.6g  %14.6g  %8.2e\n', 0, x0(1), x0(2), fx_norm );

  [ status, x2 ] = newton ( n, x0, p0, @f_lotka, @fp_lotka, tol );

  step_num = step_num + 1;

  xy(1:2,step_num) = x2(1:2,1);
  fx_norm = max ( abs ( f_lotka ( n, x2 ) ) );
  fprintf ( 1, '  %2d  %14.6g  %14.6g  %8.2e\n', step_num, x2(1), x2(2), fx_norm );
%
%  B:
%  X0 <= X2.
%  Take a step from the current point X0.
%
  x0 = x2;
  t0 = zeros ( n, 1 );
  h = 0.15;
 
  for step_num = 2 : step_max

    [ status, x2, t2, p2 ] = step ( n, x0, t0, p0, @f_lotka, @fp_lotka, h, tol );

    if ( status ~= 0 )
      fprintf ( 1, '\n' );
      fprintf ( 1, '  STEP failed!\n' );
      break
    end

    xy(1:2,step_num) = x2(1:2,1);
    fx_norm = max ( abs ( f_lotka ( n, x2 ) ) );
    fprintf ( 1, '  %2d  %14.6g  %14.6g  %8.2e\n', step_num, x2(1), x2(2), fx_norm );

    if ( p0 ~= p2 )
      fprintf ( 1, '\n' );
      fprintf ( 1, '  Switching parameters from %d to %d\n', p0, p2 );
      p0 = p2;
    end

    x0 = x2;
    t0 = t2;

  end
%
%  Plot the points.
%
  plot ( xy(1,:), xy(2,:), 'r.-', 'Markersize', 25 );
  grid ( 'on' );
  axis ( 'equal' );
  xlabel ( '<--- X --->', 'Fontsize', 16 );
  ylabel ( '<--- Y --->', 'Fontsize', 16 );
  title ( 'Lotka function.', 'Fontsize', 24 );

  filename = 'lotka_test.png';
  print ( '-dpng', filename );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

