function test13 ( )

%*****************************************************************************80
%
%% test13() computes optimal control for case #13.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    10 October 2022
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'test13():\n' );
  fprintf ( 1, '  Optimal control for case #13.\n' );
  fprintf ( 1, '  Predator-Prey Model:\n' );

  a = -0.52;
  b = -0.5;
  A = 1.0;
  B = 5.0;
  d1 = 0.1;
  d2 = 0.1;
  M = 1.0;
  x0 =  [ 10.0, 1.0, 0.0 ];
  T = 10.0;
  N = 1000;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Parameters:\n' );
  fprintf ( 1, '  a   = %g\n', a );
  fprintf ( 1, '  b   = %g\n', b );
  fprintf ( 1, '  A   = %g\n', A );
  fprintf ( 1, '  B   = %g\n', B );
  fprintf ( 1, '  d1  = %g\n', d1 );
  fprintf ( 1, '  d2  = %g\n', d2 );
  fprintf ( 1, '  M   = %g\n', M );
  fprintf ( 1, '  x0  = %g  %g  %g\n', x0 );
  fprintf ( 1, '  T   = %g\n', T );
  fprintf ( 1, '  N   = %d\n', N );

  [ t, x, u, l, cost ] = search13 ( a, b, A, B, d1, d2, M, x0, T, N );

  clf ( );
  hold ( 'on' );
    plot ( t, x(:,1), 'r-', 'linewidth', 3 );
    plot ( t, x(:,2), 'g-', 'linewidth', 3 );
    plot ( t, x(:,3), 'b-', 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- t -->' );
  ylabel ( '<-- N1/N2/z -->' );
  title ( 'State variables' );
  legend ( 'N1', 'N2', 'z' );
  filename = 'test13_x.png';
  print ( '-dpng', filename );
  fprintf ( 1, '    Graphics saved as "%s"\n', filename );

  clf ( );
  plot ( t, u, 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( '<-- t -->' );
  ylabel ( '<-- U(t) -->' );
  title ( 'Control U(t)' );
  filename = 'test13_u.png';
  print ( '-dpng', filename );
  fprintf ( 1, '    Graphics saved as "%s"\n', filename );

  clf ( );
  hold ( 'on' );
    plot ( t, l(:,1), 'linewidth', 3 );
    plot ( t, l(:,2), 'linewidth', 3 );
    plot ( t, l(:,3), 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- t -->' );
  ylabel ( '<-- \lambda -->' );
  title ( 'Adjoint \lambda(t)' );
  legend ( '\lambda_1', '\lambda_2', '\lambda_3' );
  filename = 'test13_lambda.png';
  print ( '-dpng', filename );
  fprintf ( 1, '    Graphics saved as "%s"\n', filename );

  clf ( );
  plot ( cost, 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( '<-- iteration -->' );
  ylabel ( '<-- cost -->' );
  title ( 'Cost function' );
  filename = 'test13_cost.png';
  print ( '-dpng', filename );
  fprintf ( 1, '    Graphics saved as "%s"\n', filename );

  return
end

