hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_opt_nlp2_init (e04wc)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_opt_nlp2_init (e04wc) is used to initialize the function nag_opt_nlp2_solve (e04wd).

Syntax

[iw, rw, ifail] = e04wc
[iw, rw, ifail] = nag_opt_nlp2_init

Description

nag_opt_nlp2_init (e04wc) initializes the arrays iw and rw for the function nag_opt_nlp2_solve (e04wd).

References

None.

Parameters

Compulsory Input Parameters

None.

Optional Input Parameters

None.

Output Parameters

1:     iwleniw int64int32nag_int array
2:     rwlenrw – double array
3:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
One or more of the communication array lengths leniw or lenrw is less than 600.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

The time taken by nag_opt_nlp2_init (e04wc) is negligible.

Example

function e04wc_example


fprintf('e04wc example results\n\n');

a  = [1, 1, 1, 1];
bl = [1, 1, 1, 1, -1e25, -1e25,   25];
bu = [5, 5, 5, 5,    20,    40, 1e25];
istate = zeros(7, 1, 'int64');
ccon   = zeros(2,1);
cjac   = zeros(2,4);
clamda = zeros(7,1);
hess   = zeros(4,4);
x      = [1; 5; 5; 1];

[iw, rw, ifail] = e04wc;
[majits, istate, ccon, cjac, clamda, objf, grad, hess, x, ...
                                          iw, rw, user, ifail] = ...
  e04wd(...
        a, bl, bu, @confun, @objfun, istate, ccon, cjac, clamda, ...
        hess, x, iw, rw);

fprintf('Final objective value    :   %8.1f\n',objf);
fprintf('Optimal values for x     :  ');
fprintf(' %9.2f',x);
fprintf('\nGradients at x           :  ');
fprintf(' %9.2f',grad);
fprintf('\nConstraint functions at x:  ');
fprintf(' %9.2f',ccon);
fprintf('\nNumber of major iterations  = %5d\n',majits);



function [mode, ccon, cjac, user] = ...
    confun(mode, ncnln, n, ldcj, needc, x, cjac, nstate, user)
  ccon = zeros(ncnln, 1);

  if (nstate == 1)
%  first call to confun.  set all jacobian elements to zero.
%  note that this will only work when 'derivative level = 3'
%  (the default; see section 11.2).
    cjac = zeros(ncnln, n);
  end

  if (needc(1) > 0)
    if (mode == 0  ||  mode == 2)
      ccon(1) = x(1)^2 + x(2)^2 + x(3)^2 + x(4)^2;
    end

    if (mode == 1  ||  mode == 2)
      cjac(1,1) = 2*x(1);
      cjac(1,2) = 2*x(2);
      cjac(1,3) = 2*x(3);
      cjac(1,4) = 2*x(4);
    end
  end

  if (needc(2) > 0)
    if (mode == 0  ||  mode == 2)
      ccon(2) = x(1)*x(2)*x(3)*x(4);
    end

    if (mode == 1  ||  mode == 2)
      cjac(2,1) = x(2)*x(3)*x(4);
      cjac(2,2) = x(1)*x(3)*x(4);
      cjac(2,3) = x(1)*x(2)*x(4);
      cjac(2,4) = x(1)*x(2)*x(3);
    end
  end


function [mode, objf, grad, user] = objfun(mode, n, x, grad, nstate, user)

  if (mode == 0 || mode == 2)
    objf = x(1)*x(4)*(x(1)+x(2)+x(3)) + x(3);
  end

  if (mode == 1 || mode == 2)
    grad(1) = x(4)*(2*x(1)+x(2)+x(3));
    grad(2) = x(1)*x(4);
    grad(3) = x(1)*x(4) + 1;
    grad(4) = x(1)*(x(1)+x(2)+x(3));
  end
e04wc example results

Final objective value    :       17.0
Optimal values for x     :        1.00      4.74      3.82      1.38
Gradients at x           :       14.57      1.38      2.38      9.56
Constraint functions at x:       40.00     25.00
Number of major iterations  =     6

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015