function test02 ( )

%*****************************************************************************80
%
%% test02() computes optimal control for case #2.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    01 October 2022
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'test02():\n' );
  fprintf ( 1, '  Optimal control for case #2.\n' );
  fprintf ( 1, '  Mold and Fungicide:\n' );

  r = 0.3;
  M = 10;
  A = 10.0;
  x0 = 1.0;
  T = 5.0;
  N = 1000;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Parameters:\n' );
  fprintf ( 1, '  r  = %g\n', r );
  fprintf ( 1, '  M  = %d\n', M );
  fprintf ( 1, '  A  = %g\n', A );
  fprintf ( 1, '  x0 = %g\n', x0 );
  fprintf ( 1, '  T  = %g\n', T );
  fprintf ( 1, '  N  = %d\n', N );

  [ t, x, u, lambda, cost ] = opt02 ( r, M, A, x0, T, N );

  clf ( );
  hold ( 'on' );
    plot ( t, x, 'linewidth', 3 );
    plot ( t, 0*t, 'k:' );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- t -->' );
  ylabel ( '<-- X(t) -->' );
  title ( 'State variable X(t)' );
  filename = 'test02_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 = 'test02_u.png';
  print ( '-dpng', filename );
  fprintf ( 1, '    Graphics saved as "%s"\n', filename );

  clf ( );
  plot ( t, lambda, 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( '<-- t -->' );
  ylabel ( '<-- \lambda(t) -->' );
  title ( 'Adjoint \lambda(t)' );
  filename = 'test02_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 = 'test02_cost.png';
  print ( '-dpng', filename );
  fprintf ( 1, '    Graphics saved as "%s"\n', filename );

  return
end

