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)

Purpose

nag_opt_init (e04wb) is used to initialize functions (e04dg), (e04mf), (e04nc), (e04nf), (e04nk), (e04uc), (e04uf), (e04ug) and (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: routineroutine must be a valid function name.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

lcwsav llwsav liwsav lrwsav

Output Parameters

1:     cwsav(lcwsav) – cell array of strings
2:     lwsav(llwsav) – logical array
3:     iwsav(liwsav) – int64int32nag_int array
4:     rwsav(lrwsav) – double array
5:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
The function name supplied in routine is invalid
  ifail = 2ifail=2
One or more of the workspace array lengths lcwsav, llwsav, liwsav or lrwsav is too small.

Accuracy

Not applicable.

Further Comments

The time taken by nag_opt_init (e04wb) is negligible.

Example

function nag_opt_init_example
x = [-1;
     1];
[cwsav,lwsav,iwsav,rwsav,ifail] = nag_opt_init('nag_opt_uncon_conjgrd_comp');
[iter, objf, objgrd, xOut, user, lwsavOut, iwsavOut, rwsavOut, ifail] = ...
    nag_opt_uncon_conjgrd_comp(@objfun, x, lwsav, iwsav, rwsav);
 iter, objf, objgrd, xOut, ifail

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

      expx1 = exp(x(1));
      objf = expx1*(4.0*x(1)^2+2.0*x(2)^2+4.0*x(1)*x(2)+2.0*x(2)+1.0);
      if (mode == 2)
         objgrd(1) = 4.0*expx1*(2.0*x(1)+x(2)) + objf;
         objgrd(2) = 2.0*expx1*(2.0*x(2)+2.0*x(1)+1.0);
      else
         objgrd = zeros(2,1);
      end
 

iter =

                   10


objf =

   5.3083e-14


objgrd =

   1.0e-06 *

    0.9125
    0.8316


xOut =

    0.5000
   -1.0000


ifail =

                    0


function e04wb_example
x = [-1;
     1];
[cwsav,lwsav,iwsav,rwsav,ifail] = e04wb('e04dg');
[iter, objf, objgrd, xOut, user, lwsavOut, iwsavOut, rwsavOut, ifail] = ...
    e04dg(@objfun, x, lwsav, iwsav, rwsav);
 iter, objf, objgrd, xOut, ifail

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

      expx1 = exp(x(1));
      objf = expx1*(4.0*x(1)^2+2.0*x(2)^2+4.0*x(1)*x(2)+2.0*x(2)+1.0);
      if (mode == 2)
         objgrd(1) = 4.0*expx1*(2.0*x(1)+x(2)) + objf;
         objgrd(2) = 2.0*expx1*(2.0*x(2)+2.0*x(1)+1.0);
      else
         objgrd = zeros(2,1);
      end
 

iter =

                   10


objf =

   5.3083e-14


objgrd =

   1.0e-06 *

    0.9125
    0.8316


xOut =

    0.5000
   -1.0000


ifail =

                    0



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–2013