PDF version (NAG web site
, 64bit version, 64bit version)
NAG Toolbox: nag_roots_withdraw_sys_func_easy (c05nb)
Purpose
nag_roots_withdraw_sys_func_easy (c05nb) is an easytouse function that finds a solution of a system of nonlinear equations by a modification of the Powell hybrid method.
Note: this function is scheduled to be withdrawn, please see
c05nb in
Advice on Replacement Calls for Withdrawn/Superseded Routines..
Syntax
Description
The system of equations is defined as:
nag_roots_withdraw_sys_func_easy (c05nb) is based on the MINPACK routine HYBRD1 (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 rank1 method of Broyden. At the starting point, the Jacobian is approximated by forward differences, but these are not used again until the rank1 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 MINPACK1 Technical Report ANL8074 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:
fcn – function handle or string containing name of mfile
fcn must return the values of the functions
f_{i}${f}_{i}$ at a point
x$x$.
[fvec, iflag] = fcn(n, x, iflag)
Input Parameters
 1:
n – int64int32nag_int scalar
n$n$, the number of equations.
 2:
x(n) – double array
The components of the point x$x$ at which the functions must be evaluated.
 3:
iflag – int64int32nag_int scalar
iflag > 0 ${\mathbf{iflag}}>0$.
Output Parameters
 1:
fvec(n) – double array
The function values f_{i}(x) ${f}_{i}\left(x\right)$.
 2:
iflag – 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. This value will be returned through
ifail.
 2:
x(n) – double array
n, the dimension of the array, must satisfy the constraint
n > 0 ${\mathbf{n}}>0$.
An initial guess at the solution vector.
Optional Input Parameters
 1:
n – int64int32nag_int scalar
Default:
The dimension of the array
x.
n$n$, the number of equations.
Constraint:
n > 0 ${\mathbf{n}}>0$.
 2:
xtol – double scalar
The accuracy in
x to which the solution is required.
Suggested value:
sqrt(ε)$\sqrt{\epsilon}$, where
ε$\epsilon $ is the
machine precision returned by
nag_machine_precision (x02aj).
Default:
sqrt(machine precision) $\sqrt{\mathit{machine\; precision}}$
Constraint:
xtol ≥ 0.0 ${\mathbf{xtol}}\ge 0.0$.
Input Parameters Omitted from the MATLAB Interface
 wa lwa
Output Parameters
 1:
x(n) – double array
The final estimate of the solution vector.
 2:
fvec(n) – double array
The function values at the final point returned in
x.
 3:
ifail – int64int32nag_int scalar
ifail = 0${\mathrm{ifail}}={\mathbf{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.
 W ifail < 0${\mathbf{ifail}}<0$
You have set
iflag negative in
fcn. The value of
ifail will be the same as your setting of
iflag.
 ifail = 1${\mathbf{ifail}}=1$
On entry,  n ≤ 0 ${\mathbf{n}}\le 0$, 
or  xtol < 0.0 ${\mathbf{xtol}}<0.0$. 
 W ifail = 2${\mathbf{ifail}}=2$
There have been at least
200 × (n + 1) $200\times ({\mathbf{n}}+1)$ evaluations of
fcn. Consider restarting the calculation from the final point held in
x.
 W ifail = 3${\mathbf{ifail}}=3$
No further improvement in the approximate solution
x is possible;
xtol is too small.
 ifail = 4${\mathbf{ifail}}=4$
The iteration is not making good progress. This failure exit 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_func_easy (c05nb) from a different starting point may avoid the region of difficulty.
 ifail = − 999${\mathbf{ifail}}=999$

Internal memory allocation failed.
Accuracy
If
x̂
$\hat{x}$ is the true solution,
nag_roots_withdraw_sys_func_easy (c05nb) tries to ensure that
If this condition is satisfied with
xtol
=
10^{ − k}
${\mathbf{xtol}}={10}^{k}$, then the larger components of
x$x$ have
k$k$ significant decimal digits. There is a danger that the smaller components of
x$x$ may have large relative errors, but the fast rate of convergence of
nag_roots_withdraw_sys_func_easy (c05nb) 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 = 3${\mathbf{ifail}}={\mathbf{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 are reasonably well behaved. If this condition is not satisfied, then
nag_roots_withdraw_sys_func_easy (c05nb) may incorrectly indicate convergence. The validity of the answer can be checked, for example, by rerunning
nag_roots_withdraw_sys_func_easy (c05nb) with a lower value for
xtol.
Further Comments
Local workspace arrays of fixed lengths are allocated internally by
nag_roots_withdraw_sys_func_easy (c05nb). The total size of these arrays amounts to
n × (3 × n + 13) / 2${\mathbf{n}}\times (3\times {\mathbf{n}}+13)/2$ double elements.
The time required by
nag_roots_withdraw_sys_func_easy (c05nb) to solve a given problem depends on
n$n$, the behaviour of the functions, the accuracy requested and the starting point. The number of arithmetic operations executed by
nag_roots_withdraw_sys_func_easy (c05nb) to process each call of
fcn is about
11.5 × n^{2}
$11.5\times {n}^{2}$. Unless
fcn can be evaluated quickly, the timing of
nag_roots_withdraw_sys_func_easy (c05nb) will be strongly influenced by the time spent in
fcn.
Ideally the problem should be scaled so that, at the solution, the function values are of comparable magnitude.
Example
Open in the MATLAB editor:
nag_roots_withdraw_sys_func_easy_example
function nag_roots_withdraw_sys_func_easy_example
x = [1;
1;
1;
1;
1;
1;
1;
1;
1];
[xOut, fvec, ifail] = nag_roots_withdraw_sys_func_easy(@fcn, x)
function [fvec, iflag] = fcn(n,x,iflag)
fvec = zeros(n, 1);
for k = 1:double(n)
fvec(k) = (3.02.0*x(k))*x(k)+1.0;
if k > 1
fvec(k) = fvec(k)  x(k1);
end
if k < n
fvec(k) = fvec(k)  2*x(k+1);
end
end
xOut =
0.5707
0.6816
0.7017
0.7042
0.7014
0.6919
0.6658
0.5960
0.4164
fvec =
1.0e08 *
0.6560
0.4175
0.5193
0.2396
0.2022
0.4818
0.2579
0.3884
0.0136
ifail =
0
Open in the MATLAB editor:
c05nb_example
function c05nb_example
x = [1;
1;
1;
1;
1;
1;
1;
1;
1];
[xOut, fvec, ifail] = c05nb(@fcn, x)
function [fvec, iflag] = fcn(n,x,iflag)
fvec = zeros(n, 1);
for k = 1:double(n)
fvec(k) = (3.02.0*x(k))*x(k)+1.0;
if k > 1
fvec(k) = fvec(k)  x(k1);
end
if k < n
fvec(k) = fvec(k)  2*x(k+1);
end
end
xOut =
0.5707
0.6816
0.7017
0.7042
0.7014
0.6919
0.6658
0.5960
0.4164
fvec =
1.0e08 *
0.6560
0.4175
0.5193
0.2396
0.2022
0.4818
0.2579
0.3884
0.0136
ifail =
0
PDF version (NAG web site
, 64bit version, 64bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013