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_withdraw_sys_deriv_rcomm (c05pd)

Purpose

nag_roots_withdraw_sys_deriv_rcomm (c05pd) is a comprehensive reverse communication function that finds a solution of a system of nonlinear equations by a modification of the Powell hybrid method. You must provide the Jacobian.
Note: this function is scheduled to be withdrawn, please see c05pd in Advice on Replacement Calls for Withdrawn/Superseded Routines..

Syntax

[irevcm, x, fvec, fjac, diag, r, qtf, w, lwsav, iwsav, rwsav, ifail] = c05pd(irevcm, x, fvec, fjac, diag, mode, r, qtf, w, lwsav, iwsav, rwsav, 'n', n, 'xtol', xtol, 'factor', factor)
[irevcm, x, fvec, fjac, diag, r, qtf, w, lwsav, iwsav, rwsav, ifail] = nag_roots_withdraw_sys_deriv_rcomm(irevcm, x, fvec, fjac, diag, mode, r, qtf, w, lwsav, iwsav, rwsav, 'n', n, 'xtol', xtol, 'factor', factor)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: lr no longer an optional input parameter
.

Description

The system of equations is defined as:
fi (x1,x2,,xn) = 0 ,   i = 1, 2, , n .
fi (x1,x2,,xn) = 0 ,   i= 1, 2, , n .
nag_roots_withdraw_sys_deriv_rcomm (c05pd) is based on the MINPACK routine HYBRJ (see Moré et al. (1980)). It chooses the correction at each step as a convex combination of the Newton and scaled gradient directions. The Jacobian is updated by the rank-1 method of Broyden. For more details see Powell (1970).

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
Powell M J D (1970) A hybrid method for nonlinear algebraic equations Numerical Methods for Nonlinear Algebraic Equations (ed P Rabinowitz) Gordon and Breach

Parameters

Note: this function uses reverse communication. Its use involves an initial entry, intermediate exits and re-entries, and a final exit, as indicated by the parameter irevcm. Between intermediate exits and re-entries, all parameters other than fvec and fjac must remain unchanged.

Compulsory Input Parameters

1:     irevcm – int64int32nag_int scalar
On initial entry: must have the value 00.
Constraint: irevcm = 0irevcm=0, 11, 22 or 33.
2:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n > 0 n>0 .
On initial entry: an initial guess at the solution vector.
3:     fvec(n) – double array
n, the dimension of the array, must satisfy the constraint n > 0 n>0 .
On initial entry: need not be set.
n, the dimension of the array, must satisfy the constraint n > 0 n>0 .
On intermediate re-entry: if irevcm = 1 irevcm=1 , fvec must not be changed.
If irevcm = 2 irevcm=2 , fvec must be set to the values of the functions computed at the current point x.
4:     fjac(ldfjac,n) – double array
ldfjac, the first dimension of the array, must satisfy the constraint ldfjacn ldfjacn .
On initial entry: must be set to the values of the Jacobian evaluated at the initial point x.
ldfjac, the first dimension of the array, must satisfy the constraint ldfjacn ldfjacn .
On intermediate re-entry: if irevcm3 irevcm3 , fjac must not be changed.
If irevcm = 3 irevcm=3 , fjac must be set to the value of the Jacobian computed at the current point x.
5:     diag(n) – double array
n, the dimension of the array, must satisfy the constraint n > 0 n>0 .
On initial entry: if mode = 2mode=2, diag must contain multiplicative scale factors for the variables.
Constraint: diag(i) > 0.0 diagi>0.0 , for i = 1,2,,ni=1,2,,n.
6:     mode – int64int32nag_int scalar
On initial entry: indicates whether or not you have provided scaling factors in diag.
If mode = 2mode=2 the scaling must have been supplied in diag.
Otherwise, the variables will be scaled internally.
7:     r(n × (n + 1) / 2n×(n+1)/2) – double array
On initial entry: need not be set.
8:     qtf(n) – double array
n, the dimension of the array, must satisfy the constraint n > 0 n>0 .
On initial entry: need not be set.
9:     w(n,44) – double array
10:   lwsav(22) – logical array
11:   iwsav(1515) – int64int32nag_int array
12:   rwsav(1010) – double array
The arrays lwsav, iwsav and rwsav must not be altered between calls to nag_roots_withdraw_sys_deriv_rcomm (c05pd).

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays x, fvec, diag, qtf and the first dimension of the arrays w, fjac and the second dimension of the array fjac. (An error is raised if these dimensions are not equal.)
On initial entry: nn, the number of equations.
Constraint: n > 0 n>0 .
2:     xtol – double scalar
On initial entry: the accuracy in x to which the solution is required.
Suggested value: sqrt(ε)ε, where εε is the machine precision returned by nag_machine_precision (x02aj).
Default: sqrt(machine precision) machine precision
Constraint: xtol0.0 xtol0.0 .
3:     factor – double scalar
On initial entry: a quantity to be used in determining the initial step bound. In most cases, factor should lie between 0.10.1 and 100.0100.0. (The step bound is factor × diag × x2 factor×diag×x2  if this is nonzero; otherwise the bound is factor.)
Default: 100.0100.0
Constraint: factor > 0.0 factor>0.0 .

Input Parameters Omitted from the MATLAB Interface

ldfjac

Output Parameters

1:     irevcm – int64int32nag_int scalar
On intermediate exit: specifies what action you must take before re-entering nag_roots_withdraw_sys_deriv_rcomm (c05pd) with irevcm unchanged. The value of irevcm should be interpreted as follows:
irevcm = 1 irevcm=1
Indicates the start of a new iteration. No action is required by you, but x and fvec are available for printing.
irevcm = 2 irevcm=2
Indicates that before re-entry to nag_roots_withdraw_sys_deriv_rcomm (c05pd), fvec must contain the function values fi(x) fi(x) .
irevcm = 3 irevcm=3
Indicates that before re-entry to nag_roots_withdraw_sys_deriv_rcomm (c05pd), fjac(i,j) fjacij  must contain the value of (fi)/(xj) fi xj  at the point xx, for i = 1,2,,ni=1,2,,n and j = 1,2,,nj=1,2,,n.
On final exit: irevcm = 0 irevcm=0 , and the algorithm has terminated.
2:     x(n) – double array
On intermediate exit: contains the current point.
On final exit: the final estimate of the solution vector.
3:     fvec(n) – double array
On final exit: the function values at the final point, x.
4:     fjac(ldfjac,n) – double array
ldfjacn ldfjacn .
On final exit: the orthogonal matrix QQ produced by the QR QR  factorization of the final approximate Jacobian.
5:     diag(n) – double array
On intermediate exit: the scale factors actually used (computed internally if mode2mode2).
6:     r(n × (n + 1) / 2n×(n+1)/2) – double array
On intermediate exit: must not be changed.
On final exit: the upper triangular matrix RR produced by the QR QR  factorization of the final approximate Jacobian, stored row-wise.
7:     qtf(n) – double array
On intermediate exit: must not be changed.
On final exit: the vector QTf QTf .
8:     w(n,44) – double array
9:     lwsav(22) – logical array
10:   iwsav(1515) – int64int32nag_int array
11:   rwsav(1010) – double array
12:   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.

  ifail = 1ifail=1
On entry, n0 n0 ,
or xtol < 0.0 xtol<0.0 ,
or factor0.0 factor0.0 ,
or ldfjac < n ldfjac<n ,
or mode = 2 mode=2  and diag(i)0.0 diagi0.0  for some ii, i = 1, 2, , n i= 1, 2, , n .
  ifail = 2ifail=2
On entry, irevcm < 0 irevcm<0  or irevcm > 3 irevcm>3 .
W ifail = 3ifail=3
No further improvement in the approximate solution x is possible; xtol is too small.
W ifail = 4ifail=4
The iteration is not making good progress, as measured by the improvement from the last five Jacobian evaluations.
W ifail = 5ifail=5
The iteration is not making good progress, as measured by the improvement from the last ten iterations.
A value of ifail = 4ifail=4 or 55 may indicate that the system does not have a zero, or that the solution is very close to the origin (see Section [Accuracy]). Otherwise, rerunning nag_roots_withdraw_sys_deriv_rcomm (c05pd) from a different starting point may avoid the region of difficulty.

Accuracy

If x^  is the true solution and DD denotes the diagonal matrix whose entries are defined by the array diag, then nag_roots_withdraw_sys_deriv_rcomm (c05pd) tries to ensure that
D(x)2 xtol × D2 .
D (x-x^) 2 xtol × D x^ 2 .
If this condition is satisfied with xtol = 10k xtol = 10-k , then the larger components of Dx Dx  have kk significant decimal digits. There is a danger that the smaller components of Dx Dx  may have large relative errors, but the fast rate of convergence of nag_roots_withdraw_sys_deriv_rcomm (c05pd) usually obviates this possibility.
If xtol is less than machine precision and the above test is satisfied with the machine precision in place of xtol, then the function exits with ifail = 3ifail=3.
Note:  this convergence test is based purely on relative error, and may not indicate convergence if the solution is very close to the origin.
The test assumes that the functions and the Jacobian are coded consistently and that the functions are reasonably well behaved. If these conditions are not satisfied, then nag_roots_withdraw_sys_deriv_rcomm (c05pd) may incorrectly indicate convergence. The coding of the Jacobian can be checked using nag_roots_withdraw_sys_deriv_check (c05za). If the Jacobian is coded correctly, then the validity of the answer can be checked by rerunning nag_roots_withdraw_sys_deriv_rcomm (c05pd) with a lower value for xtol.

Further Comments

The time required by nag_roots_withdraw_sys_deriv_rcomm (c05pd) to solve a given problem depends on nn, the behaviour of the functions, the accuracy requested and the starting point. The number of arithmetic operations executed by nag_roots_withdraw_sys_deriv_rcomm (c05pd) is about 11.5 × n2 11.5×n2  to process each evaluation of the functions and about 1.3 × n3 1.3×n3  to process each evaluation of the Jacobian. The timing of nag_roots_withdraw_sys_deriv_rcomm (c05pd) is strongly influenced by the time spent in the evaluation of the functions and the Jacobian.
Ideally the problem should be scaled so that, at the solution, the function values are of comparable magnitude.

Example

function nag_roots_withdraw_sys_deriv_rcomm_example
irevcm = int64(0);
x = [-1;
     -1;
     -1;
     -1;
     -1;
     -1;
     -1;
     -1;
     -1];
fvec = zeros(9, 1);
fjac = zeros(9,9);
diag = [1; 1; 1; 1; 1; 1; 1; 1; 1];
mode = int64(2);
r = zeros(45,1);
qtf = zeros(9,1);
w = zeros(9, 4);
lwsav = false(5, 1);
iwsav = zeros(15, 1, 'int64');
rwsav = zeros(10, 1);
[irevcm, x, fvec, fjac, diag, r, qtf, w, lwsav, iwsav, rwsav, ifail] = ...
      nag_roots_withdraw_sys_deriv_rcomm(irevcm, x, fvec, fjac, diag, mode, r, qtf, w, lwsav, iwsav, rwsav);
while (irevcm > 0)
  if (irevcm == 2)
    for i=1:9
      fvec(i) = (3-2*x(i))*x(i)+1;
      if (i > 1)
        fvec(i) = fvec(i) - x(i-1);
      end
      if (i < 9)
        fvec(i) = fvec(i) - 2*x(i+1);
      end
    end
  end
  [irevcm, x, fvec, fjac, diag, r, qtf, w, lwsav, iwsav, rwsav, ifail] = ...
      nag_roots_withdraw_sys_deriv_rcomm(irevcm, x, fvec, fjac, diag, mode, r, qtf, w, lwsav, iwsav, rwsav);
end
  x
 

x =

   -0.5707
   -0.6816
   -0.7017
   -0.7042
   -0.7014
   -0.6919
   -0.6658
   -0.5960
   -0.4164


function c05pd_example
irevcm = int64(0);
x = [-1;
     -1;
     -1;
     -1;
     -1;
     -1;
     -1;
     -1;
     -1];
fvec = zeros(9, 1);
fjac = zeros(9,9);
diag = [1; 1; 1; 1; 1; 1; 1; 1; 1];
mode = int64(2);
r = zeros(45,1);
qtf = zeros(9,1);
w = zeros(9, 4);
lwsav = false(5, 1);
iwsav = zeros(15, 1, 'int64');
rwsav = zeros(10, 1);
[irevcm, x, fvec, fjac, diag, r, qtf, w, lwsav, iwsav, rwsav, ifail] = ...
      c05pd(irevcm, x, fvec, fjac, diag, mode, r, qtf, w, lwsav, iwsav, rwsav);
while (irevcm > 0)
  if (irevcm == 2)
    for i=1:9
      fvec(i) = (3-2*x(i))*x(i)+1;
      if (i > 1)
        fvec(i) = fvec(i) - x(i-1);
      end
      if (i < 9)
        fvec(i) = fvec(i) - 2*x(i+1);
      end
    end
  end
  [irevcm, x, fvec, fjac, diag, r, qtf, w, lwsav, iwsav, rwsav, ifail] = ...
      c05pd(irevcm, x, fvec, fjac, diag, mode, r, qtf, w, lwsav, iwsav, rwsav);
end
  x
 

x =

   -0.5707
   -0.6816
   -0.7017
   -0.7042
   -0.7014
   -0.6919
   -0.6658
   -0.5960
   -0.4164



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