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_init (e04wb)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_opt_init (e04wb) is used to initialize functions nag_opt_uncon_conjgrd_comp (e04dg), nag_opt_lp_solve (e04mf), nag_opt_lsq_lincon_solve (e04nc), nag_opt_qp_dense_solve (e04nf), nag_opt_qpconvex1_sparse_solve (e04nk), nag_opt_nlp1_solve (e04uc), nag_opt_nlp1_rcomm (e04uf), nag_opt_nlp1_sparse_solve (e04ug) and nag_opt_lsq_gencon_deriv (e04us).

Syntax

[cwsav, lwsav, iwsav, rwsav, ifail] = e04wb(routine)
[cwsav, lwsav, iwsav, rwsav, ifail] = nag_opt_init(routine)

Description

nag_opt_init (e04wb) initializes some or all of the arrays cwsav, lwsav, iwsav and rwsav for the function specified by routine, and any associated option setting functions.

References

None.

Parameters

Compulsory Input Parameters

1:     routine – string
The name of the function to be initialized.
Constraint: routine must be a valid function name.

Optional Input Parameters

None.

Output Parameters

1:     cwsavlcwsav – cell array of strings
2:     lwsavllwsav – logical array
3:     iwsavliwsav int64int32nag_int array
4:     rwsavlrwsav – double array
5:     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
The function name supplied in routine is invalid
   ifail=2
One or more of the workspace array lengths lcwsav, llwsav, liwsav or lrwsav is too small.
   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_init (e04wb) is negligible.

Example

The use of nag_opt_init (e04wb) is illustrated by the example programs of the functions listed in Purpose.
function e04wb_example


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

x = [-1   1];
% Initialize
[cwsav,lwsav,iwsav,rwsav,ifail] = e04wb('e04dg');

% Optimize
[iter, objf, objgrd, x, user, lwsav, iwsav, rwsav, ifail] = ...
e04dg( ...
       @objfun, x, lwsav, iwsav, rwsav);

fprintf('Variable          Value     Gradient value\n');
for i=1:2
 fprintf('Varbl %3d    %12.8f    %9.1e\n', i, x(i), objgrd(i));
end
fprintf('\nFinal objective value = %15.7e\n',objf);



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

  expx1 = exp(x(1));
  objf = expx1*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1);
  if (mode == 2)
    objgrd(1) = 4*expx1*(2*x(1)+x(2)) + objf;
    objgrd(2) = 2*expx1*(2*x(2)+2*x(1)+1);
  else
    objgrd = zeros(2,1);
  end
e04wb example results

Variable          Value     Gradient value
Varbl   1      0.50000001      9.1e-07
Varbl   2     -0.99999989      8.3e-07

Final objective value =   5.3083002e-14

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