PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_roots_sys_deriv_rcomm (c05rd)
Purpose
nag_roots_sys_deriv_rcomm (c05rd) 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.
Syntax
[
irevcm,
x,
fvec,
fjac,
diag,
r,
qtf,
iwsav,
rwsav,
ifail] = c05rd(
irevcm,
x,
fvec,
fjac,
mode,
diag,
r,
qtf,
iwsav,
rwsav, 'n',
n, 'xtol',
xtol, 'factor',
factor)
[
irevcm,
x,
fvec,
fjac,
diag,
r,
qtf,
iwsav,
rwsav,
ifail] = nag_roots_sys_deriv_rcomm(
irevcm,
x,
fvec,
fjac,
mode,
diag,
r,
qtf,
iwsav,
rwsav, 'n',
n, 'xtol',
xtol, 'factor',
factor)
Description
The system of equations is defined as:
nag_roots_sys_deriv_rcomm (c05rd) 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 argument
irevcm. Between intermediate exits and re-entries,
all arguments other than fvec and fjac must remain unchanged.
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
On initial entry: must have the value .
Constraint:
, , or .
- 2:
– double array
-
On initial entry: an initial guess at the solution vector.
- 3:
– double array
-
On initial entry: need not be set.
On intermediate re-entry: if
,
fvec must not be changed.
If
,
fvec must be set to the values of the functions computed at the current point
x.
- 4:
– double array
-
On initial entry: need not be set.
On intermediate re-entry: if
,
fjac must not be changed.
If ,
must contain the value of at the point , for and .
- 5:
– int64int32nag_int scalar
-
On initial entry: indicates whether or not you have provided scaling factors in
diag.
If
the scaling must have been supplied in
diag.
Otherwise, if , the variables will be scaled internally.
Constraint:
or .
- 6:
– double array
-
On initial entry: if
,
diag must contain multiplicative scale factors for the variables.
If
,
diag need not be set.
Constraint:
if , , for .
- 7:
– double array
-
On initial entry: need not be set.
- 8:
– double array
-
On initial entry: need not be set.
- 9:
– int64int32nag_int array
- 10:
– double array
-
The arrays
iwsav and
rwsav must not be altered between calls to
nag_roots_sys_deriv_rcomm (c05rd).
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the arrays
x,
fvec,
diag,
qtf and the first dimension of the array
fjac and the second dimension of the array
fjac. (An error is raised if these dimensions are not equal.)
, the number of equations.
Constraint:
.
- 2:
– double scalar
Suggested value:
, where
is the
machine precision returned by
nag_machine_precision (x02aj).
Default:
On initial entry: the accuracy in
x to which the solution is required.
Constraint:
.
- 3:
– double scalar
Default:
On initial entry: a quantity to be used in determining the initial step bound. In most cases,
factor should lie between
and
. (The step bound is
if this is nonzero; otherwise the bound is
factor.)
Constraint:
.
Output Parameters
- 1:
– int64int32nag_int scalar
-
On intermediate exit:
specifies what action you must take before re-entering
nag_roots_sys_deriv_rcomm (c05rd) with irevcm unchanged. The value of
irevcm should be interpreted as follows:
- Indicates the start of a new iteration. No action is required by you, but x and fvec are available for printing.
- Indicates that before re-entry to nag_roots_sys_deriv_rcomm (c05rd), fvec must contain the function values .
- Indicates that before re-entry to nag_roots_sys_deriv_rcomm (c05rd),
must contain the value of at the point , for and .
On final exit: , and the algorithm has terminated.
- 2:
– double array
-
On intermediate exit:
contains the current point.
On final exit: the final estimate of the solution vector.
- 3:
– double array
-
On final exit: the function values at the final point,
x.
- 4:
– double array
-
On final exit: the orthogonal matrix produced by the factorization of the final approximate Jacobian.
- 5:
– double array
-
On intermediate exit:
diag must not be changed.
On final exit: the scale factors actually used (computed internally if ).
- 6:
– double array
-
On intermediate exit:
must not be changed.
On final exit: the upper triangular matrix produced by the factorization of the final approximate Jacobian, stored row-wise.
- 7:
– double array
-
On intermediate exit:
must not be changed.
On final exit: the vector .
- 8:
– int64int32nag_int array
- 9:
– double array
-
- 10:
– int64int32nag_int scalar
On final exit:
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.
-
-
Constraint: , , or .
- W
-
No further improvement in the solution is possible.
- W
-
The iteration is not making good progress, as measured by the improvement from the last
Jacobian evaluations. This failure exit may indicate that the system does not have a zero, or that the solution is very close to the origin (see
Accuracy). Otherwise, rerunning
nag_roots_sys_deriv_rcomm (c05rd) from a different starting point may avoid the region of difficulty.
- W
-
The iteration is not making good progress, as measured by the improvement from the last
iterations. This failure exit may indicate that the system does not have a zero, or that the solution is very close to the origin (see
Accuracy). Otherwise, rerunning
nag_roots_sys_deriv_rcomm (c05rd) from a different starting point may avoid the region of difficulty.
-
-
Constraint: .
-
-
Constraint: .
-
-
Constraint: or .
-
-
Constraint: .
-
-
On entry,
and
diag contained a non-positive element.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
If
is the true solution and
denotes the diagonal matrix whose entries are defined by the array
diag, then
nag_roots_sys_deriv_rcomm (c05rd) tries to ensure that
If this condition is satisfied with
, then the larger components of
have
significant decimal digits. There is a danger that the smaller components of
may have large relative errors, but the fast rate of convergence of
nag_roots_sys_deriv_rcomm (c05rd) 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
.
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 convergence 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_sys_deriv_rcomm (c05rd) may incorrectly indicate convergence. The coding of the Jacobian can be checked using
nag_roots_sys_deriv_check (c05zd). If the Jacobian is coded correctly, then the validity of the answer can be checked by rerunning
nag_roots_sys_deriv_rcomm (c05rd) with a lower value for
xtol.
Further Comments
The time required by nag_roots_sys_deriv_rcomm (c05rd) to solve a given problem depends on , the behaviour of the functions, the accuracy requested and the starting point. The number of arithmetic operations executed by nag_roots_sys_deriv_rcomm (c05rd) is approximately to process each evaluation of the functions and approximately to process each evaluation of the Jacobian. The timing of nag_roots_sys_deriv_rcomm (c05rd) is strongly influenced by the time spent evaluating the functions.
Ideally the problem should be scaled so that, at the solution, the function values are of comparable magnitude.
Example
This example determines the values
which satisfy the tridiagonal equations:
Open in the MATLAB editor:
c05rd_example
function c05rd_example
fprintf('c05rd example results\n\n');
x = -ones(9, 1);
diagnl = ones(9,1);
mode = int64(2);
irevcm = int64(0);
fjac = zeros(9, 9);
fvec = zeros(9, 1);
qtf = zeros(9, 1);
r = zeros(45, 1);
rwsav = zeros(46, 1);
iwsav = zeros(17, 1, 'int64');
icount = int64(0);
first = true;
while (irevcm ~= 0 || first )
first = false;
[irevcm, x, fvec, fjac, diag, r, qtf, iwsav, rwsav, ifail] = ...
c05rd(irevcm, x, fvec, fjac, mode, diagnl, r, qtf, iwsav, rwsav);
switch irevcm
case {1}
icount = icount + 1;
case {2}
fvec(1:9) = (3.0-2.0.*x).*x + 1.0;
fvec(2:9) = fvec(2:9) - x(1:8);
fvec(1:8) = fvec(1:8) - 2.0.*x(2:9);
case {3}
fjac = zeros(9, 9);
for k = 1:9
fjac(k,k) = 3 - 4*x(k);
if (k ~= 1)
fjac(k,k-1) = -1;
end
if (k ~= 9)
fjac(k,k+1) = -2;
end
end
end
end
switch ifail
case {0}
fprintf('\nFinal 2-norm of the residuals after %d iterations = %12.4e\n',...
icount, norm(fvec));
fprintf('\nFinal approximate solution\n');
disp(x);
case {3, 4, 5}
fprintf('\nApproximate solution\n');
disp(x);
end
c05rd example results
Final 2-norm of the residuals after 11 iterations = 1.1926e-08
Final approximate solution
-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)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015