PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_roots_sys_deriv_expert (c05rc)
Purpose
nag_roots_sys_deriv_expert (c05rc) is a comprehensive 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
[
x,
fvec,
fjac,
diag,
nfev,
njev,
r,
qtf,
user,
ifail] = c05rc(
fcn,
x,
mode,
diag,
nprint, 'n',
n, 'xtol',
xtol, 'maxfev',
maxfev, 'factor',
factor, 'user',
user)
[
x,
fvec,
fjac,
diag,
nfev,
njev,
r,
qtf,
user,
ifail] = nag_roots_sys_deriv_expert(
fcn,
x,
mode,
diag,
nprint, 'n',
n, 'xtol',
xtol, 'maxfev',
maxfev, 'factor',
factor, 'user',
user)
Description
The system of equations is defined as:
nag_roots_sys_deriv_expert (c05rc) 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. At the starting point, the Jacobian is requested, but it is not asked for again until the rank-1 method fails to produce satisfactory progress. 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
Compulsory Input Parameters
- 1:
– function handle or string containing name of m-file
-
Depending upon the value of
iflag,
fcn must either return the values of the functions
at a point
or return the Jacobian at
.
[fvec, fjac, user, iflag] = fcn(n, x, fvec, fjac, user, iflag)
Input Parameters
- 1:
– int64int32nag_int scalar
-
, the number of equations.
- 2:
– double array
-
The components of the point at which the functions or the Jacobian must be evaluated.
- 3:
– double array
-
If
or
,
fvec contains the function values
and must not be changed.
- 4:
– double array
-
If
,
contains the value of
at the point
, for
and
. When
or
,
fjac must not be changed.
- 5:
– Any MATLAB object
fcn is called from
nag_roots_sys_deriv_expert (c05rc) with the object supplied to
nag_roots_sys_deriv_expert (c05rc).
- 6:
– int64int32nag_int scalar
-
,
or
.
- x, fvec and fjac are available for printing (see nprint).
- fvec is to be updated.
- fjac is to be updated.
Output Parameters
- 1:
– double array
-
If
on entry,
fvec must contain the function values
(unless
iflag is set to a negative value by
fcn).
- 2:
– double array
-
If
on entry,
must contain the value of
at the point
, for
and
, (unless
iflag is set to a negative value by
fcn).
- 3:
– Any MATLAB object
- 4:
– int64int32nag_int scalar
-
In general,
iflag should not be reset by
fcn. If, however, you wish to terminate execution (perhaps because some illegal point
x has been reached), then
iflag should be set to a negative integer value.
- 2:
– double array
-
An initial guess at the solution vector.
- 3:
– int64int32nag_int scalar
-
Indicates whether or not you have provided scaling factors in
diag.
If
the scaling must have been specified in
diag.
Otherwise, if , the variables will be scaled internally.
Constraint:
or .
- 4:
– double array
-
If
,
diag must contain multiplicative scale factors for the variables.
If
,
diag need not be set.
Constraint:
if , , for .
- 5:
– int64int32nag_int scalar
-
Indicates whether (and how often) special calls to
fcn, with
iflag set to
, are to be made for printing purposes.
- No calls are made.
- fcn is called at the beginning of the first iteration, every nprint iterations thereafter and immediately before the return from nag_roots_sys_deriv_expert (c05rc).
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the arrays
x,
diag. (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:
The accuracy in
x to which the solution is required.
Constraint:
.
- 3:
– int64int32nag_int scalar
Default:
The maximum number of calls to
fcn with
.
nag_roots_sys_deriv_expert (c05rc) will exit with
, if, at the end of an iteration, the number of calls to
fcn exceeds
maxfev.
Constraint:
.
- 4:
– double scalar
Default:
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:
.
- 5:
– Any MATLAB object
user is not used by
nag_roots_sys_deriv_expert (c05rc), but is passed to
fcn. Note that for large objects it may be more efficient to use a global variable which is accessible from the m-files than to use
user.
Output Parameters
- 1:
– double array
-
The final estimate of the solution vector.
- 2:
– double array
-
The function values at the final point returned in
x.
- 3:
– double array
-
The orthogonal matrix produced by the factorization of the final approximate Jacobian.
- 4:
– double array
-
The scale factors actually used (computed internally if ).
- 5:
– int64int32nag_int scalar
-
The number of calls made to
fcn to evaluate the functions.
- 6:
– int64int32nag_int scalar
-
The number of calls made to
fcn to evaluate the Jacobian.
- 7:
– double array
-
The upper triangular matrix produced by the factorization of the final approximate Jacobian, stored row-wise.
- 8:
– double array
-
The vector .
- 9:
– Any MATLAB object
- 10:
– int64int32nag_int scalar
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
-
There have been at least
maxfev calls to
fcn.
- 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_expert (c05rc) 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_expert (c05rc) from a different starting point may avoid the region of difficulty.
- W
-
iflag was set negative in
fcn.
-
-
Constraint: .
-
-
Constraint: .
-
-
Constraint: or .
-
-
Constraint: .
-
-
On entry,
and
diag contained a non-positive element.
-
-
Constraint: .
-
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_expert (c05rc) 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_expert (c05rc) 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_expert (c05rc) 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_expert (c05rc) with a lower value for
xtol.
Further Comments
Local workspace arrays of fixed lengths are allocated internally by nag_roots_sys_deriv_expert (c05rc). The total size of these arrays amounts to double elements.
The time required by nag_roots_sys_deriv_expert (c05rc) 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_expert (c05rc) 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_expert (c05rc) 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:
c05rc_example
function c05rc_example
fprintf('c05rc example results\n\n');
x = -ones(9, 1);
diag = ones(9, 1);
mode = int64(2);
nprint = int64(0);
[xOut, fvec, fjac, diag, nfev, njev, r, qtf, user, ifail] = ...
c05rc(@fcn, x, mode, diag, nprint);
switch ifail
case {0}
fprintf('\nFinal 2-norm of the residuals = %12.4e\n', norm(fvec));
fprintf('\nFinal approximate solution\n');
disp(xOut);
case {2, 3, 4}
fprintf('\nApproximate solution\n');
disp(xOut);
end
function [fvec, fjac, user, iflag] = fcn(n, x, fvec, fjac, user, iflag)
coeff = [-1, 3, -2, -2, -1];
nd = double(n);
if (iflag == 0)
elseif (iflag == 1)
fvec(1:nd) = (coeff(2)+coeff(3)*x(1:nd)).*x(1:nd) - coeff(5);
fvec(2:nd) = fvec(2:nd) + coeff(1)*x(1:(nd-1));
fvec(1:(nd-1)) = fvec(1:(nd-1)) + coeff(4)*x(2:nd);
else
fjac = zeros(nd, nd);
fjac(1,1) = coeff(2) + 2*coeff(3)*x(1);
fjac(1,2) = coeff(4);
for k = 2:nd-1
fjac(k,k-1) = coeff(1);
fjac(k,k) = coeff(2) + 2*coeff(3)*x(k);
fjac(k,k+1) = coeff(4);
end
fjac(nd,nd-1) = coeff(1);
fjac(nd,nd) = coeff(2) + 2*coeff(3)*x(nd);
end
c05rc example results
Final 2-norm of the residuals = 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