function test14 ( )

%*****************************************************************************80
%
%% test14() computes optimal control for case #14.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 October 2022
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'test14():\n' );
  fprintf ( 1, '  Optimal control for case #14.\n' );
  fprintf ( 1, '  Invasive Plant Species:\n' );

  B = 5.0;
  k = 1.0;
  x0 = [ 0.5, 1.0, 1.5, 2.0, 10.0 ];
  N = 10;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Parameters:\n' );
  fprintf ( 1, '  B  = %g\n', B );
  fprintf ( 1, '  k  = %g\n', k );
  fprintf ( 1, '  x0 = %g %g %g %g %g\n', x0 );
  fprintf ( 1, '  N  = %d\n', N );

  [ t, x, u, l, cost ] = opt14 ( B, k, x0, 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 ( '<-- r -->' );
  title ( 'State variables' );
  legend ( 'x1', 'x2', 'x3', 'x4', 'x5' );
  filename = 'test14_x.png';
  print ( '-dpng', filename );
  fprintf ( 1, '    Graphics saved as "%s"\n', filename );

  clf ( );
  hold ( 'on' );
    plot ( t(1:N), u(1:N,1), 'linewidth', 3 );
    plot ( t(1:N), u(1:N,2), 'linewidth', 3 );
    plot ( t(1:N), u(1:N,3), 'linewidth', 3 );
    plot ( t(1:N), u(1:N,4), 'linewidth', 3 );
    plot ( t(1:N), u(1:N,5), 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- t -->' );
  ylabel ( '<-- U(t) -->' );
  title ( 'Control U(t)' );
  legend ( 'u1', 'u2', 'u3', 'u4', 'u5' );
  filename = 'test14_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 );
    plot ( t, l(:,4), 'linewidth', 3 );
    plot ( t, l(:,5), 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- t -->' );
  ylabel ( '<-- \lambda(t) -->' );
  title ( 'Adjoint \lambda(t)' );
  legend ( '\lambda_1', '\lambda_2', '\lambda_3', '\lambda_4', '\lambda_5' );
  filename = 'test14_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 = 'test14_cost.png';
  print ( '-dpng', filename );
  fprintf ( 1, '    Graphics saved as "%s"\n', filename );

  return
end

