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_quad_opt_get (d01zl)

Purpose

nag_quad_opt_get (d01zl) is used to query the current value associated with an optional parameter for nag_quad_1d_gen_vec_multi_rcomm (d01ra).

Syntax

[ivalue, rvalue, cvalue, optype, ifail] = d01zl(optstr, iopts, opts)
[ivalue, rvalue, cvalue, optype, ifail] = nag_quad_opt_get(optstr, iopts, opts)

Description

nag_quad_opt_get (d01zl) is used to query the current value associated with optional parameters. It is necessary to initialize optional parameter arrays, iopts and opts, using nag_quad_opt_set (d01zk) before any optional parameters are queried.
nag_quad_opt_get (d01zl) will normally return either an integer, real or character value dependent upon the type associated with the optional parameter being queried. Some real and integer optional parameters also return additional information in cvalue. Whether the optional parameter queried is of integer, real or character type, and whether additional information is returned in cvalue, is indicated by the returned value of optype.
Information on optional parameter names and whether these options are real, integer or character can be found in Section [Optional Parameters] in (d01ra).

References

None.

Parameters

Compulsory Input Parameters

1:     optstr – string
A string identifying the option whose current value is required. See Section [Optional Parameters] in (d01ra) for information on valid optional parameters. In addition, the following is a valid option:
IdentifyIdentify
In which case nag_quad_opt_get (d01zl) returns in cvalue the 66 character function name supplied to nag_quad_opt_set (d01zk) when the optional parameter arrays iopts and opts were initialized.
2:     iopts( : :) – int64int32nag_int array
Note: the contents of iopts must not have been altered between calls to nag_quad_opt_set (d01zk), nag_quad_opt_get (d01zl) and the selected problem solving routine.
3:     opts( : :) – double array
Note: the contents of opts must not have been altered between calls to nag_quad_opt_set (d01zk), nag_quad_opt_get (d01zl) and the selected problem solving routine.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     ivalue – int64int32nag_int scalar
If the optional parameter supplied in optstr is an integer valued parameter, ivalue will hold that value.
2:     rvalue – double scalar
If the optional parameter supplied in optstr is a real valued parameter, rvalue will hold that value.
3:     cvalue – string
Note: the string returned in cvalue will never exceed 4040 characters in length.
If the optional parameter supplied in optstr is a character valued parameter, cvalue will hold that value. cvalue will also contain additional information for some integer and real valued parameters, as indicated by optype.
4:     optype – int64int32nag_int scalar
Indicates whether the optional parameter supplied in optstr is an integer, real or character valued parameter and hence which of ivalue, rvalue or cvalue holds the current value.
optype = 1optype=1
optstr is an integer valued optional parameter; its current value has been returned in ivalue.
optype = 2optype=2
optstr is a real valued optional parameter; its current value has been returned in rvalue.
optype = 3optype=3
optstr is a character valued optional parameter; its current value has been returned in cvalue.
optype = 4optype=4
optstr is an integer valued optional parameter; its current value has been returned in ivalue. Additional information has been returned in cvalue.
optype = 5optype=5
optstr is a real valued optional parameter; its current value has been returned in rvalue. Additional information has been returned in cvalue.
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:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

W ifail = 11ifail=11
On entry, the optional parameter in optstr was not recognized.
  ifail = 41ifail=41
On entry, optstr indicates a character optional parameter, but cvalue is too short to hold the stored value. The returned value will be truncated.
  ifail = 61ifail=61
The arrays iopts and opts have either not been initialized, have become corrupted, or are not compatible with this option setting function. The arrays iopts and opts have either not been initialized, have become corrupted, or are not compatible with this option setting function. The arrays iopts and opts have either not been initialized, have become corrupted, or are not compatible with this option setting function. The arrays iopts and opts have either not been initialized, have become corrupted, or are not compatible with this option setting function. The arrays iopts and opts have either not been initialized, have become corrupted, or are not compatible with this option setting function.
  ifail = 999ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

None.

Example

function nag_quad_opt_get_example

  % Setup phase.

  % set problem parameters
  ni = int64(2);
  nx = int64(0);
  % lower (a) and upper (b) bounds
  a = 0;
  b = pi;
  iopts = zeros(100, 1, 'int64');
  opts  = zeros(100, 1);

  % initialize option arrays
  [iopts, opts, ifail] = nag_quad_opt_set('Initialize = nag_quad_1d_gen_vec_multi_rcomm', iopts, opts);

  % set any non-default options required
  [iopts, opts, ifail] = nag_quad_opt_set('Quadrature Rule = gk41', iopts, opts);
  [iopts, opts, ifail] = nag_quad_opt_set('Absolute Tolerance = 1.0e-7', iopts, opts);
  [iopts, opts, ifail] = nag_quad_opt_set('Relative Tolerance = 1.0e-7', iopts, opts);

  % determine maximum required array lengths
  [lenxrq, ldfmrq, sdfmrq, licmin, licmax, lcmin, lcmax, ifail] = ...
        nag_quad_1d_gen_vec_multi_dimreq(ni, iopts, opts);

  % allocate remaining arrays
  needi  = zeros(ni, 1, 'int64');
  comm   = zeros(lcmax, 1);
  icomm  = zeros(licmax, 1, 'int64');
  fm     = zeros(ldfmrq, sdfmrq);
  dinest = zeros(ni, 1);
  errest = zeros(ni, 1);
  x      = zeros(1, lenxrq);

  % Solve phase.

  % Use nag_quad_1d_gen_vec_multi_rcomm to evaluate the definate integrals of:
  %   f_1 = (x*sin(2*x))*cos(15*x)
  %   f_2 = (x*sin(2*x))*(x*cos(50*x))

  % set initial irevcm
  irevcm = int64(1);

  while irevcm ~= 0
    [irevcm, sid, needi, x, nx, dinest, errest, icomm, comm, ifail] = ...
      nag_quad_1d_gen_vec_multi_rcomm(irevcm, a, b, needi, x, nx, fm, dinest, errest, ...
            iopts, opts, icomm, comm);

    switch irevcm
      case 11
        % Initial returns.
        % These will occur during the non-adaptive phase.
        % All values must be supplied.
        % dinest and errest do not contain approximations
        % over the complete interval at this stage.

        % Calculate x*sin(2*x), storing the result in fm(2,1:nx) for re-use.
        fm(2, :) = x.*sin(2*x);

        % Calculate f_1
        fm(1, :) = fm(2, :).*cos(15*x);

        % Calculate f_2
        fm(2, :) = fm(2, :).*x.*cos(50*x);
      case 12
        % Intermediate returns.
        % These will occur during the adaptive phase.
        % All requested values must be supplied.
        % dinest and errest do not contain approximations
        % over the complete interval at this stage.

        % Calculate x*sin(2*x).
        fm(2, :) = x.*sin(2*x);

        % Calculate f_1 if required
        if needi(1) == 1
          fm(1, :) = fm(2, :).*cos(15*x);
        end

        % Complete f_2 calculation if required.
        if needi(2) == 1
          fm(2, :) = fm(2, :).*x.*cos(50*x);
        end
      case 0
        % Final return
    end
  end

  % query some currently set options and statistics.
  [ivalue, rvalue, cvalue, optype, ifail] = nag_quad_opt_get('Quadrature rule', iopts, opts);
  display_option('Quadrature rule',optype,ivalue,rvalue,cvalue);
  [ivalue, rvalue, cvalue, optype, ifail] = nag_quad_opt_get('Maximum Subdivisions', iopts, opts);
  display_option('Maximum Subdivisions',optype,ivalue,rvalue,cvalue);
  [ivalue, rvalue, cvalue, optype, ifail] = nag_quad_opt_get('Extrapolation', iopts, opts);
  display_option('Extrapolation',optype,ivalue,rvalue,cvalue);
  [ivalue, rvalue, cvalue, optype, ifail] = nag_quad_opt_get('Extrapolation Safeguard', iopts, opts);
  display_option('Extrapolation Safeguard',optype,ivalue,rvalue,cvalue);

  % print solution
  fprintf('\nIntegral |  needi  |   dinest   |   errest   \n');
  for j=1:ni
    fprintf('%9d %9d %12.4e %12.4e\n', j, needi(j), dinest(j), errest(j));
  end


function [dinest, errest, user] = monit(ni, ns, dinest, errest, fcount, ...
                                        sinfoi, evals, ldi, sinfor, fs, ...
                                        es, ldr, user)
  % Display information on individual segments
  fprintf('\nInformation on splitting and evaluations over subregions.\n');
  for k=1:ns
    sid = sinfoi(1,k);
    parent = sinfoi(2,k);
    child1 = sinfoi(3,k);
    child2 = sinfoi(4,k);
    level = sinfoi(5,k);
    lbnd = sinfor(1,k);
    ubnd = sinfor(2,k);
    fprintf('\nSegment %3d Sid = %3d Parent = %3d Level = %3d.\n', k, sid, parent, level);
    if (child1>0)
      fprintf('Children = (%3d, %3d)\n', child1, child2);
    end
    fprintf('Bounds (%11.4e, %11.4e)\n', lbnd, ubnd);
    for j = 1:ni
      if (evals(j,k) ~= 0)
        fprintf('Integral %2d approximation %11.4e\n', j, fs(j,k));
        fprintf('Integral %2d error estimate %11.4e\n', j, es(j,k));
        if (evals(j,k) ~= 1)
          fprintf('Integral %2d evaluation has been superseded by descendants.\n', j);
        end
      end
    end
  end
function display_option(optstr,optype,ivalue,rvalue,cvalue)
  % Query optype and print the appropriate option values

  switch optype
    case 1
      fprintf('%30s: %13d\n', optstr, ivalue);
    case 2
      fprintf('%30s: %13.4e\n', optstr, rvalue);
    case 3
      fprintf('%30s: %16s\n', optstr, cvalue);
    case 4
      fprintf('%30s: %3d  %16s\n', optstr, ivalue, cvalue);
    case 5
      fprintf('%30s: %14.4e  %16s\n', optstr, rvalue, cvalue);
  end
 
               Quadrature rule: GK41                            
          Maximum Subdivisions:            50
                 Extrapolation: ON                              
       Extrapolation Safeguard:    1.0000e-12

Integral |  needi  |   dinest   |   errest   
        1         0  -2.8431e-02   1.1234e-14
        2         0   7.9083e-03   2.6600e-09

function d01zl_example

  % Setup phase.

  % set problem parameters
  ni = int64(2);
  nx = int64(0);
  % lower (a) and upper (b) bounds
  a = 0;
  b = pi;
  iopts = zeros(100, 1, 'int64');
  opts  = zeros(100, 1);

  % initialize option arrays
  [iopts, opts, ifail] = d01zk('Initialize = d01ra', iopts, opts);

  % set any non-default options required
  [iopts, opts, ifail] = d01zk('Quadrature Rule = gk41', iopts, opts);
  [iopts, opts, ifail] = d01zk('Absolute Tolerance = 1.0e-7', iopts, opts);
  [iopts, opts, ifail] = d01zk('Relative Tolerance = 1.0e-7', iopts, opts);

  % determine maximum required array lengths
  [lenxrq, ldfmrq, sdfmrq, licmin, licmax, lcmin, lcmax, ifail] = ...
        d01rc(ni, iopts, opts);

  % allocate remaining arrays
  needi  = zeros(ni, 1, 'int64');
  comm   = zeros(lcmax, 1);
  icomm  = zeros(licmax, 1, 'int64');
  fm     = zeros(ldfmrq, sdfmrq);
  dinest = zeros(ni, 1);
  errest = zeros(ni, 1);
  x      = zeros(1, lenxrq);

  % Solve phase.

  % Use d01ra to evaluate the definate integrals of:
  %   f_1 = (x*sin(2*x))*cos(15*x)
  %   f_2 = (x*sin(2*x))*(x*cos(50*x))

  % set initial irevcm
  irevcm = int64(1);

  while irevcm ~= 0
    [irevcm, sid, needi, x, nx, dinest, errest, icomm, comm, ifail] = ...
      d01ra(irevcm, a, b, needi, x, nx, fm, dinest, errest, ...
            iopts, opts, icomm, comm);

    switch irevcm
      case 11
        % Initial returns.
        % These will occur during the non-adaptive phase.
        % All values must be supplied.
        % dinest and errest do not contain approximations
        % over the complete interval at this stage.

        % Calculate x*sin(2*x), storing the result in fm(2,1:nx) for re-use.
        fm(2, :) = x.*sin(2*x);

        % Calculate f_1
        fm(1, :) = fm(2, :).*cos(15*x);

        % Calculate f_2
        fm(2, :) = fm(2, :).*x.*cos(50*x);
      case 12
        % Intermediate returns.
        % These will occur during the adaptive phase.
        % All requested values must be supplied.
        % dinest and errest do not contain approximations
        % over the complete interval at this stage.

        % Calculate x*sin(2*x).
        fm(2, :) = x.*sin(2*x);

        % Calculate f_1 if required
        if needi(1) == 1
          fm(1, :) = fm(2, :).*cos(15*x);
        end

        % Complete f_2 calculation if required.
        if needi(2) == 1
          fm(2, :) = fm(2, :).*x.*cos(50*x);
        end
      case 0
        % Final return
    end
  end

  % query some currently set options and statistics.
  [ivalue, rvalue, cvalue, optype, ifail] = d01zl('Quadrature rule', iopts, opts);
  display_option('Quadrature rule',optype,ivalue,rvalue,cvalue);
  [ivalue, rvalue, cvalue, optype, ifail] = d01zl('Maximum Subdivisions', iopts, opts);
  display_option('Maximum Subdivisions',optype,ivalue,rvalue,cvalue);
  [ivalue, rvalue, cvalue, optype, ifail] = d01zl('Extrapolation', iopts, opts);
  display_option('Extrapolation',optype,ivalue,rvalue,cvalue);
  [ivalue, rvalue, cvalue, optype, ifail] = d01zl('Extrapolation Safeguard', iopts, opts);
  display_option('Extrapolation Safeguard',optype,ivalue,rvalue,cvalue);

  % print solution
  fprintf('\nIntegral |  needi  |   dinest   |   errest   \n');
  for j=1:ni
    fprintf('%9d %9d %12.4e %12.4e\n', j, needi(j), dinest(j), errest(j));
  end


function [dinest, errest, user] = monit(ni, ns, dinest, errest, fcount, ...
                                        sinfoi, evals, ldi, sinfor, fs, ...
                                        es, ldr, user)
  % Display information on individual segments
  fprintf('\nInformation on splitting and evaluations over subregions.\n');
  for k=1:ns
    sid = sinfoi(1,k);
    parent = sinfoi(2,k);
    child1 = sinfoi(3,k);
    child2 = sinfoi(4,k);
    level = sinfoi(5,k);
    lbnd = sinfor(1,k);
    ubnd = sinfor(2,k);
    fprintf('\nSegment %3d Sid = %3d Parent = %3d Level = %3d.\n', k, sid, parent, level);
    if (child1>0)
      fprintf('Children = (%3d, %3d)\n', child1, child2);
    end
    fprintf('Bounds (%11.4e, %11.4e)\n', lbnd, ubnd);
    for j = 1:ni
      if (evals(j,k) ~= 0)
        fprintf('Integral %2d approximation %11.4e\n', j, fs(j,k));
        fprintf('Integral %2d error estimate %11.4e\n', j, es(j,k));
        if (evals(j,k) ~= 1)
          fprintf('Integral %2d evaluation has been superseded by descendants.\n', j);
        end
      end
    end
  end
function display_option(optstr,optype,ivalue,rvalue,cvalue)
  % Query optype and print the appropriate option values

  switch optype
    case 1
      fprintf('%30s: %13d\n', optstr, ivalue);
    case 2
      fprintf('%30s: %13.4e\n', optstr, rvalue);
    case 3
      fprintf('%30s: %16s\n', optstr, cvalue);
    case 4
      fprintf('%30s: %3d  %16s\n', optstr, ivalue, cvalue);
    case 5
      fprintf('%30s: %14.4e  %16s\n', optstr, rvalue, cvalue);
  end
 
               Quadrature rule: GK41                            
          Maximum Subdivisions:            50
                 Extrapolation: ON                              
       Extrapolation Safeguard:    1.0000e-12

Integral |  needi  |   dinest   |   errest   
        1         0  -2.8431e-02   1.1234e-14
        2         0   7.9083e-03   2.6600e-09


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