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_1d_gen_vec_multi_dimreq (d01rc)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

The dimension of the arrays that must be passed as actual arguments to nag_quad_1d_gen_vec_multi_rcomm (d01ra) are dependent upon a number of factors. nag_quad_1d_gen_vec_multi_dimreq (d01rc) returns the correct size of these arrays enabling nag_quad_1d_gen_vec_multi_rcomm (d01ra) to be called successfully.

Syntax

[lenxrq, ldfmrq, sdfmrq, licmin, licmax, lcmin, lcmax, ifail] = d01rc(ni, iopts, opts)
[lenxrq, ldfmrq, sdfmrq, licmin, licmax, lcmin, lcmax, ifail] = nag_quad_1d_gen_vec_multi_dimreq(ni, iopts, opts)

Description

nag_quad_1d_gen_vec_multi_dimreq (d01rc) returns the minimum dimension of the arrays x (lenxrq), fm (ldfmrq×sdfmrq), icom (licmin) and com (lcmin) that must be passed to nag_quad_1d_gen_vec_multi_rcomm (d01ra) to enable the integration to commence given options currently set for the ni integrands. nag_quad_1d_gen_vec_multi_dimreq (d01rc) also returns the upper bounds licmax and lcmax for the dimension of the arrays icom and com, that could possibly be required with the chosen options.
All the minimum values lenxrq, ldfmrq, sdfmrq, licmin and lcmin, and subsequently all the maximum values licmax and lcmax may be affected if different options are set, and hence nag_quad_1d_gen_vec_multi_dimreq (d01rc) should be called after any options are set, and before the first call to nag_quad_1d_gen_vec_multi_rcomm (d01ra).
A segment is here defined as a (possibly maximal) subset of the domain of integration. During subdivision, a segment is bisected into two new segments.

References

None.

Parameters

Compulsory Input Parameters

1:     ni int64int32nag_int scalar
ni, the number of integrals which will be approximated in the subsequent call to nag_quad_1d_gen_vec_multi_rcomm (d01ra).
Constraint: ni>0.
2:     iopts: int64int32nag_int array
Note: the dimension of this array is dictated by the requirements of associated functions that must have been previously called. This array must be the same array passed as argument iopts in the previous call to nag_quad_opt_set (d01zk).
The integer option array as returned by nag_quad_opt_set (d01zk).
Constraint: iopts must not be changed between calls to nag_quad_opt_set (d01zk), nag_quad_opt_get (d01zl), nag_quad_1d_gen_vec_multi_dimreq (d01rc) and nag_quad_1d_gen_vec_multi_rcomm (d01ra).
3:     opts: – double array
Note: the dimension of this array is dictated by the requirements of associated functions that must have been previously called. This array must be the same array passed as argument opts in the previous call to nag_quad_opt_set (d01zk).
The real option array as returned by nag_quad_opt_set (d01zk).
Constraint: opts must not be changed between calls to nag_quad_opt_set (d01zk), nag_quad_opt_get (d01zl), nag_quad_1d_gen_vec_multi_dimreq (d01rc) and nag_quad_1d_gen_vec_multi_rcomm (d01ra).

Optional Input Parameters

None.

Output Parameters

1:     lenxrq int64int32nag_int scalar
lenxrq, the minimum dimension of the array x that can be used in a subsequent call to nag_quad_1d_gen_vec_multi_rcomm (d01ra).
2:     ldfmrq int64int32nag_int scalar
ldfmrq, the minimum leading dimension of the array fm that can be used in a subsequent call to nag_quad_1d_gen_vec_multi_rcomm (d01ra).
3:     sdfmrq int64int32nag_int scalar
sdfmrq, the minimum second dimension of the array fm that can be used in a subsequent call to nag_quad_1d_gen_vec_multi_rcomm (d01ra).
Note: the minimum dimension of the array fm is ldfmrq×sdfmrq.
4:     licmin int64int32nag_int scalar
licmin, the minimum dimension of the array icom that must be passed to nag_quad_1d_gen_vec_multi_rcomm (d01ra) to enable it to calculate a single approximation to all the ni integrals over the interval a,b with spri initial segments.
5:     licmax int64int32nag_int scalar
licmax the dimension of the array icom that must be passed to nag_quad_1d_gen_vec_multi_rcomm (d01ra) to enable it to exhaust the adaptive process controlled by the currently set options for the ni integrals over the interval a,b with spri initial segments.
6:     lcmin int64int32nag_int scalar
lcmin, the minimum dimension of the array com that must be passed to nag_quad_1d_gen_vec_multi_rcomm (d01ra) to enable it to calculate a single approximation to all the ni integrals over the interval a,b with spri initial segments.
7:     lcmax int64int32nag_int scalar
lcmax, the dimension of the array com that must be passed to nag_quad_1d_gen_vec_multi_rcomm (d01ra) to enable it to exhaust the adaptive process controlled by the currently set options for the ni integrals over the interval a,b with spri initial segments.
8:     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=21
Constraint: ni>0.
   ifail=1001
One of the option arrays iopts or opts has become corrupted. Re-initialize the arrays using nag_quad_opt_set (d01zk).
   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

None.

Example

See Example in nag_quad_1d_gen_vec_multi_rcomm (d01ra) for examples of the usage of nag_quad_1d_gen_vec_multi_dimreq (d01rc).
function d01rc_example


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


  % 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', k, sid);
    fprintf(' Parent = %3d Level = %3d.\n', 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));
      end
      if (evals(j,k) ~= 1)
        fprintf('Integral %2d evaluation', j);
        fprintf(' has been superseded by descendants.\n');
      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
d01rc example results

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