function test03 ( )

%*****************************************************************************80
%
%% test03() computes optimal control for case #3.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    06 October 2022
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'test03():\n' );
  fprintf ( 1, '  Optimal control for case #3.\n' );
  fprintf ( 1, '  Bacteria:\n' );

  r = 1.0;
  A = 1.0;
  B = 12.0;
  C = 1.0;
  x0 = 1.0;
  T = 1.0;
  N = 1000;

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

  [ t, x, u, lambda, cost ] = opt03 ( r, A, B, C, 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 = 'test03_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 = 'test03_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 = 'test03_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 = 'test03_cost.png';
  print ( '-dpng', filename );
  fprintf ( 1, '    Graphics saved as "%s"\n', filename );

  return
end

