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_sparse_init (e04vg)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_opt_nlp2_sparse_init (e04vg) is used to initialize the function nag_opt_nlp2_sparse_solve (e04vh).

Syntax

[cw, iw, rw, ifail] = e04vg
[cw, iw, rw, ifail] = nag_opt_nlp2_sparse_init

Description

nag_opt_nlp2_sparse_init (e04vg) initializes the arrays cw, iw and rw for the function nag_opt_nlp2_sparse_solve (e04vh).

References

None.

Parameters

Compulsory Input Parameters

None.

Optional Input Parameters

None.

Output Parameters

1:     cwlencw – cell array of strings
2:     iwleniw int64int32nag_int array
3:     rwlenrw – double array
4:     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 lencw, 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_sparse_init (e04vg) is negligible.

Example

function e04vg_example


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

start  = int64(0);
objadd = 0;
objrow = int64(6);
prob  = '        ';
iarow = int64([1;2;4;4;5;5;6;6]);
iacol = int64([3;4;1;2;1;2;3;4]);
nea   = int64(8);
a     = [ -1; -1; -1;  1;  1; -1;  3;  2];
igrow = int64([1;1;2;2;3;3;6;6]);
igcol = int64([1;2;1;2;1;2;3;4]);
neg   = int64(8);

xlow  = [-0.55;  -0.55;    0;    0];
xupp  = [ 0.55;   0.55; 1200; 1200];
x     = [ 0;      0;       0;    0];
xnames = {' '};
xstate = zeros(4, 1, 'int64');

flow  = [-894.8; -894.8; -1294.8; -0.55; -0.55; -1e25];
fupp  = [-894.8; -894.8; -1294.8;  1e25;  1e25;  1e25];
f     = [   0;      0;       0;       0;     0;     0];
fnames = {' '};
fstate = zeros(6, 1, 'int64');
fmul   = zeros(6, 1);
ns     = int64(0);

[cw, iw, rw, ifail] = e04vg;

[x, xstate, xmul, f, fstate, fmul, ns, ninf, sinf, ...
                                   cw, iw, rw, cuser, ifail] = ...
     e04vh(...
           start, objadd, objrow, prob, @usrfun, iarow, iacol, ...
           nea, a, igrow, igcol, neg, xlow, xupp, xnames, flow, fupp, ...
           fnames, x, xstate, f, fstate, fmul, ns, cw, iw, rw);
% x, xstate, xmul, f, fstate, fmul, ns, ninf, sinf, ifail

fprintf('Final objective value  :   %8.1f\n',f(objrow));
fprintf('Optimal values for x   :  ');
fprintf(' %9.2f',x);
fprintf('\n');



function [status, f, g, user] = ...
  usrfun(status, n, x, needf, nf, f, needg, leng, g, user)

  if (needf > 0)
%   The nonlinear components of f_i(x) need to be assigned,
    f(1) = 1000*sin(-x(1)-0.25) + 1000*sin(-x(2) -0.25);
    f(2) = 1000*sin(x(1)-0.25) + 1000*sin(x(1)-x(2) -0.25);
    f(3) = 1000*sin(x(2)-x(1)-0.25) + 1000*sin(x(2) -0.25);
%   n.b. in this example there is no need to assign for the wholly
%   linear components f_4(x) and f_5(x).
    f(6) = 1.0d-6*x(3)^3 + 2.0d-6*x(4)^3/3;
  end

  if (needg > 0)
%   The derivatives of the function f_i(x) need to be assigned.
%   G(k) should be set to partial derivative df_i(x)/dx_j where
%   i = IGFUN(k) and j = IGVAR(k), for k = 1 to LENG.
    g(1) = -1000*cos(-x(1)-0.25);
    g(2) = -1000*cos(-x(2)-0.25);
    g(3) =  1000*cos(x(1)-0.25)      + 1000*cos(x(1)-x(2) -0.25);
    g(4) = -1000*cos(x(1)-x(2)-0.25);
    g(5) = -1000*cos(x(2)-x(1)-0.25);
    g(6) =  1000*cos(x(2)-x(1)-0.25) + 1000*cos(x(2) -0.25);
    g(7) = 3.0d-6*x(3)^2;
    g(8) = 2.0d-6*x(4)^2;
  end
e04vg example results

Final objective value  :     5126.5
Optimal values for x   :        0.12     -0.40    679.95   1026.07

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