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_roots_sys_deriv_check (c05zd)

Purpose

nag_roots_sys_deriv_check (c05zd) checks the user-supplied gradients of a set of nonlinear functions in several variables, for consistency with the functions themselves. The function must be called twice.

Syntax

[xp, err, ifail] = c05zd(mode, x, fvec, fjac, fvecp, 'm', m, 'n', n)
[xp, err, ifail] = nag_roots_sys_deriv_check(mode, x, fvec, fjac, fvecp, 'm', m, 'n', n)

Description

nag_roots_sys_deriv_check (c05zd) is based on the MINPACK routine CHKDER (see Moré et al. (1980)). It checks the iith gradient for consistency with the iith function by computing a forward-difference approximation along a suitably chosen direction and comparing this approximation with the user-supplied gradient along the same direction. The principal characteristic of nag_roots_sys_deriv_check (c05zd) is its invariance under changes in scale of the variables or functions.

References

Moré J J, Garbow B S and Hillstrom K E (1980) User guide for MINPACK-1 Technical Report ANL-80-74 Argonne National Laboratory

Parameters

Compulsory Input Parameters

1:     mode – int64int32nag_int scalar
The value 11 on the first call and the value 22 on the second call of nag_roots_sys_deriv_check (c05zd).
Constraint: mode = 1mode=1 or 22.
2:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n1n1.
The components of a point xx, at which the consistency check is to be made. (See Section [Accuracy].)
3:     fvec(m) – double array
m, the dimension of the array, must satisfy the constraint m1m1.
If mode = 2mode=2, fvec must contain the value of the functions evaluated at xx. If mode = 1mode=1, fvec is not referenced.
4:     fjac(m,n) – double array
m, the first dimension of the array, must satisfy the constraint m1m1.
If mode = 2mode=2, fjac must contain the value of (fi)/(xj) fi xj  at the point xx, for i = 1,2,,mi=1,2,,m and j = 1,2,,nj=1,2,,n. If mode = 1mode=1, fjac is not referenced.
5:     fvecp(m) – double array
m, the dimension of the array, must satisfy the constraint m1m1.
If mode = 2mode=2, fvecp must contain the value of the functions evaluated at xp (as output by a preceding call to nag_roots_sys_deriv_check (c05zd) with mode = 1mode=1). If mode = 1mode=1, fvecp is not referenced.

Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The dimension of the arrays fvec, fvecp and the first dimension of the array fjac. (An error is raised if these dimensions are not equal.)
mm, the number of functions.
Constraint: m1m1.
2:     n – int64int32nag_int scalar
Default: The dimension of the array x and the second dimension of the array fjac. (An error is raised if these dimensions are not equal.)
Constraint: n1n1.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     xp(n) – double array
If mode = 1mode=1, xp is set to a point neighbouring x. If mode = 2mode=2, xp is undefined.
2:     err(m) – double array
If mode = 2mode=2, err contains measures of correctness of the respective gradients. If mode = 1mode=1, err is undefined. If there is no loss of significance (see Section [Accuracy]), then if err(i)erri is 1.01.0 the iith user-supplied gradient (fi)/(xj) fi xj , for j = 1,2,,nj=1,2,,n is correct, whilst if err(i)erri is 0.00.0 the iith gradient is incorrect. For values of err(i)erri between 0.00.0 and 1.01.0 the categorisation is less certain. In general, a value of err(i) > 0.5erri>0.5 indicates that the iith gradient is probably correct.
3:     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
Constraint: mode = 1mode=1 or 22.
  ifail = 2ifail=2
Constraint: m1m1.
  ifail = 3ifail=3
Constraint: n1n1.

Accuracy

nag_roots_sys_deriv_check (c05zd) does not perform reliably if cancellation or rounding errors cause a severe loss of significance in the evaluation of a function. Therefore, none of the components of xx should be unusually small (in particular, zero) or any other value which may cause loss of significance. The relative differences between corresponding elements of fvecp and fvec should be at least two orders of magnitude greater than the machine precision returned by nag_machine_precision (x02aj).

Further Comments

The time required by nag_roots_sys_deriv_check (c05zd) increases with m and n.

Example

function nag_roots_sys_deriv_check_example
% Point at which to check gradients:
x = [0.92, 0.13, 0.54];

fvec  = zeros(15, 1);
fjac  = zeros(15, 3);
fvecp = zeros(15, 1);

y = 0.01*[14, 18, 22, 25, 29, 32, 35, 39, 47, 58, 73, 96, 134, 210, 439];

[xp, err, ifail] = nag_roots_sys_deriv_check(int64(1), x, fvec, fjac, fvecp);

for i=1:15
  u = i;
  v = 16 - i;
  w = min(u, v);
  fvec(i)  = y(i) - (x(1)+u/(v*x(2)+w*x(3)));
  fvecp(i) = y(i) - (xp(1)+u/(v*xp(2)+w*xp(3)));
  denom = (v*x(2)+w*x(3))^(-2);
  fjac(i,:) = [-1, u*v*denom, u*w*denom];
end

[xp, err, ifail] = nag_roots_sys_deriv_check(int64(2), x, fvec, fjac, fvecp);

fprintf('\nAt point %12.4f %12.4f %12.4f\n', x);
if any(err <= 0.5)
  for i=1:15
    if err(i) <= 0.5
      fprintf('Suspicious gradient number %d with error measure %12.4f\n', i, err(i));
    end
  end
else
  fprintf('Gradients appear correct\n');
end
 

At point       0.9200       0.1300       0.5400
Gradients appear correct

function c05zd_example
% Point at which to check gradients:
x = [0.92, 0.13, 0.54];

fvec  = zeros(15, 1);
fjac  = zeros(15, 3);
fvecp = zeros(15, 1);

y = 0.01*[14, 18, 22, 25, 29, 32, 35, 39, 47, 58, 73, 96, 134, 210, 439];

[xp, err, ifail] = c05zd(int64(1), x, fvec, fjac, fvecp);

for i=1:15
  u = i;
  v = 16 - i;
  w = min(u, v);
  fvec(i)  = y(i) - (x(1)+u/(v*x(2)+w*x(3)));
  fvecp(i) = y(i) - (xp(1)+u/(v*xp(2)+w*xp(3)));
  denom = (v*x(2)+w*x(3))^(-2);
  fjac(i,:) = [-1, u*v*denom, u*w*denom];
end

[xp, err, ifail] = c05zd(int64(2), x, fvec, fjac, fvecp);

fprintf('\nAt point %12.4f %12.4f %12.4f\n', x);
if any(err <= 0.5)
  for i=1:15
    if err(i) <= 0.5
      fprintf('Suspicious gradient number %d with error measure %12.4f\n', i, err(i));
    end
  end
else
  fprintf('Gradients appear correct\n');
end
 

At point       0.9200       0.1300       0.5400
Gradients appear correct


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