function test10 ( )

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

  a = 1.0;
  b = 1.0;
  c = 1.0;
  x10 = 0.75;
  A = 2.0;
  D = 0.5;
  T = 0.3;
  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, '  x10 = %g\n', x10 );
  fprintf ( 1, '  A   = %g\n', A );
  fprintf ( 1, '  D   = %g\n', D );
  fprintf ( 1, '  T   = %g\n', T );
  fprintf ( 1, '  N   = %g\n', N );

  [ t, x, u, l, cost ] = opt10 ( a, b, c, x10, A, D, T, N );

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

  return
end

