function test08 ( )

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

  s = 10.0;
  m1 = 0.02;
  m2 = 0.5;
  m3 = 4.4;
  r = 0.03;
  tmax = 1500;
  k = 0.000024;
  p = 300;
  T0 = 800;
  Ti0 = 0.04;
  V0 = 1.5;
  A = 0.05;
  T = 20;
  N = 1000;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Parameters:\n' );
  fprintf ( 1, '  s    = %g\n', s );
  fprintf ( 1, '  m1   = %g\n', m1 );
  fprintf ( 1, '  m2   = %g\n', m2 );
  fprintf ( 1, '  m3   = %g\n', m3 );
  fprintf ( 1, '  r    = %g\n', r );
  fprintf ( 1, '  tmax = %g\n', tmax );
  fprintf ( 1, '  k    = %g\n', k );
  fprintf ( 1, '  p    = %g\n', p );
  fprintf ( 1, '  T0   = %g\n', T0 );
  fprintf ( 1, '  Ti0  = %g\n', Ti0 );
  fprintf ( 1, '  V0   = %g\n', V0 );
  fprintf ( 1, '  A    = %g\n', A );
  fprintf ( 1, '  T    = %g\n', T );
  fprintf ( 1, '  N    = %d\n', N );

  [ t, x, u, l, cost ] = opt08 ( s, m1, m2, m3, r, tmax, k, p, T0, Ti0, V0, ...
    A, T, N );

  clf ( );
  hold ( 'on' );
    plot ( t, x(:,1), 'r-', 'linewidth', 3 );
    plot ( t, x(:,2), 'b--', 'linewidth', 3 );
    plot ( t, x(:,3), 'g:', 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- t -->' );
  ylabel ( '<-- T/Ti/V -->' );
  title ( 'State variables' );
  legend ( 'T', 'Ti', 'V' );
  filename = 'test08_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 = 'test08_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(t) -->' );
  title ( 'Adjoints \lambda(t)' );
  legend ( '\lambda_1', '\lambda_2', '\lambda_3' );
  filename = 'test08_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 = 'test08_cost.png';
  print ( '-dpng', filename );
  fprintf ( 1, '    Graphics saved as "%s"\n', filename );

  return
end

