function test07 ( )

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

  a = 0.2;
  b = 0.525;
  c = 0.001;
  d = 0.5;
  e = 0.5;
  q = 0.1;
  S0 = 1000.0;
  E0 = 100.0;
  I0 = 50.0;
  R0 = 15.0;
  P0 = S0 + E0 + I0 + R0;
  A = 0.1;
  T = 20.0;
  N = 1000;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Parameters:\n' );
  fprintf ( 1, '  a  = %g\n', a );
  fprintf ( 1, '  b  = %g\n', b );
  fprintf ( 1, '  c  = %g\n', c );
  fprintf ( 1, '  d  = %g\n', d );
  fprintf ( 1, '  e  = %g\n', e );
  fprintf ( 1, '  q  = %g\n', q );
  fprintf ( 1, '  S0 = %g\n', S0 );
  fprintf ( 1, '  E0 = %g\n', E0 );
  fprintf ( 1, '  I0 = %g\n', I0 );
  fprintf ( 1, '  R0 = %g\n', R0 );
  fprintf ( 1, '  P0 = %g\n', P0 );
  fprintf ( 1, '  A  = %g\n', A );
  fprintf ( 1, '  T  = %g\n', T );
  fprintf ( 1, '  N  = %d\n', N );

  [ t, x, u, lambda, cost ] ...
    = opt07 ( a, b, c, d, e, q, S0, E0, I0, R0, P0, A, T, N );

  clf ( );
  hold ( 'on' );
    plot ( t, x(:,1), 'linewidth', 3 );
    plot ( t, x(:,2), 'linewidth', 3 );
    plot ( t, x(:,3), 'linewidth', 3 );
    plot ( t, x(:,4), 'linewidth', 3 );
    plot ( t, x(:,5), 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- t -->' );
  ylabel ( '<-- S/E/I/R/P(t) -->' );
  title ( 'State variables' );
  legend ( 'S', 'E', 'I', 'R', 'P' );
  filename = 'test07_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 = 'test07_u.png';
  print ( '-dpng', filename );
  fprintf ( 1, '    Graphics saved as "%s"\n', filename );

  clf ( );
  hold ( 'on' );
    plot ( t, lambda(:,1), 'linewidth', 3 );
    plot ( t, lambda(:,2), 'linewidth', 3 );
    plot ( t, lambda(:,3), 'linewidth', 3 );
    plot ( t, lambda(:,4), 'linewidth', 3 );
    plot ( t, lambda(:,5), 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- t -->' );
  ylabel ( '<-- \lambda(t) -->' );
  title ( 'Adjoints \lambda(t)' );
  legend ( '\lambda_1', '\lambda_2', '\lambda_3', '\lambda_4', '\lambda_5' )
  filename = 'test07_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 = 'test07_cost.png';
  print ( '-dpng', filename );
  fprintf ( 1, '    Graphics saved as "%s"\n', filename );

  return
end

