function test01 ( )

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

  A = 1.0;
  B = 1.0;
  C = 1.0;
  x0 = 1.0;
  T = 1.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, '  x0 = %g\n', x0 );
  fprintf ( 1, '  T  = %g\n', T );
  fprintf ( 1, '  N  = %d\n', N );


  [ t, x, u, lambda, cost ] = opt01 ( A, B, C, x0, T, N );

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

  return
end

