function quadprog_test ( )

%*****************************************************************************80
%
%% quadprog_test() tests quadprog().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    27 March 2019
%
%  Author:
%
%    John Burkardt
%
  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'quadprog_test\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  quadprog() solves quadratic programming problems:\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  minimize    1/2 x'' H x + f'' x\n' );
  fprintf ( 1, '  subject to: A x <= b\n' );
  fprintf ( 1, '              B x =  c\n' );
  fprintf ( 1, '              d <= x <= e\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  H should be positive definite symmetric.\n' );

  quadprog_test01 ( );
  quadprog_test02 ( );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'quadprog_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  return
end
function quadprog_test01 ( )

%*****************************************************************************80
%
%% quadprog_test01() runs a simple test case.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    27 March 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'quadprog_test01:\n' );
  fprintf ( 1, '  minimize    1/2 x1^2 + x2^2 - x1x2 - 2x1 - 6x2\n' );
  fprintf ( 1, '  subject to:  x1 +  x2 <= 2\n' );
  fprintf ( 1, '              -x1 + 2x2 <= 2\n' );
  fprintf ( 1, '              2x1 +  x2 <= 3\n' );

  H = [ 1.0, -1.0; ...
       -1.0,  2.0 ];

  f = [ -2.0; -6.0 ];

  A = [  1.0, 1.0; ...
        -1.0, 2.0; ...
         2.0, 1.0 ];

  b = [ 2.0; 2.0; 3.0 ];

  options = optimoptions ( @quadprog, 'Display', 'off' );

  [ x, fval, exitflag ] = quadprog ( H, f, A, b, [], [], [], [], [], options );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Solution vector x = [ %g; %g]:\n', x(1), x(2) );
  fprintf ( 1, '  Function value at x is %g\n', fval );
  fprintf ( 1, '  Exitflag is %d\n', exitflag );

  return
end
function quadprog_test02 ( )

%*****************************************************************************80
%
%% quadprog_test02() runs a simple test case.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    27 March 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'quadprog_test02:\n' );
  fprintf ( 1, '  minimize    65/2 x^2 - 22xy + 7y^2 - 16xz + 7yz + 5/2z^2\n' );
  fprintf ( 1, '              - 13x + 15y + 7z\n' );
  fprintf ( 1, '  subject to:  x + 2y + z <=  3\n' );
  fprintf ( 1, '              2x      + z <=  2\n' );
  fprintf ( 1, '              -x + 2y - z <= -2\n' );

  H = [  65.0, -22.0, -16.0; ...
        -22.0,  14.0,   7.0; ...
        -16.0,   7.0,   5.0 ];

  f = [ - 13.0; 15.0; 7.0 ];

  A = [  1.0, 2.0,  1.0; ...
         2.0, 0.0,  1.0; ...
        -1.0, 2.0, -1.0 ];

  b = [ 3.0; 2.0; -2.0 ];

  options = optimoptions ( @quadprog, 'Display', 'off' );

  [ x, fval, exitflag ] = quadprog ( H, f, A, b, [], [], [], [], [], options );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Solution vector x = [ %g; %g; %g]:\n', x(1), x(2), x(3) );
  fprintf ( 1, '  Function value at x is %g\n', fval );
  fprintf ( 1, '  Exitflag is %d\n', exitflag );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

