Integer type:** int32**** int64**** nag_int** show int32 show int32 show int64 show int64 show nag_int show nag_int

nag_roots_withdraw_sys_func_rcomm (c05nd) is a comprehensive reverse communication function that finds a solution of a system of nonlinear equations by a modification of the Powell hybrid method.

Mark 23: lr no longer an optional input parameter

.The system of equations is defined as:

nag_roots_withdraw_sys_func_rcomm (c05nd) is based on the MINPACK routine HYBRD (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 approximated by forward differences, but these are not used again until the rank-1 method fails to produce satisfactory progress. For more details see Powell (1970).

f _{i}
(x_{1},x_{2}, … ,x_{n})
=
0
,
i =
1,
2,
… ,
n
.
$${f}_{i}({x}_{1},{x}_{2},\dots ,{x}_{n})=0\text{, \hspace{1em}}i=1,2,\dots ,n\text{.}$$ |

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

- 1: irevcm – int64int32nag_int scalar
*On initial entry*: must have the value 0$0$.- 2: x(n) – double array
*On initial entry*: an initial guess at the solution vector.- 3: fvec(n) – double array
*On initial entry*: need not be set.- 4: ml – int64int32nag_int scalar
- 5: mu – int64int32nag_int scalar
- 6: diag(n) – double array
*On initial entry*: if mode = 2${\mathbf{mode}}=2$, diag must contain multiplicative scale factors for the variables.*Constraint*: diag(i) > 0.0 ${\mathbf{diag}}\left(\mathit{i}\right)>0.0$, for i = 1,2, … ,n$\mathit{i}=1,2,\dots ,n$.- 7: mode – int64int32nag_int scalar
- 8: fjac(ldfjac,n) – double array
- ldfjac, the first dimension of the array, must satisfy the constraint ldfjac ≥ n $\mathit{ldfjac}\ge {\mathbf{n}}$.
*On initial entry*: need not be set. - 9: r(n × (n + 1) / 2${\mathbf{n}}\times ({\mathbf{n}}+1)/2$) – double array
*On initial entry*: need not be set.- 10: qtf(n) – double array
*On initial entry*: need not be set.- 11: w(n,4$4$) – double array

- 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*: n$n$, the number of equations.- 2: xtol – double scalar
*On initial entry*: 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}}$- 3: epsfcn – double scalar
*On initial entry*: the order of the largest relative error in the functions. It is used in determining a suitable step for a forward difference approximation to the Jacobian. If epsfcn is less than machine precision (returned by nag_machine_precision (x02aj)) then machine precision is used. Consequently a value of 0.0$0.0$ will often be suitable.*Default*: 0.0$0.0$- 4: 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.1$0.1$ and 100.0$100.0$. (The step bound is factor × ‖diag × x‖_{2}${\mathbf{factor}}\times {\Vert {\mathbf{diag}}\times {\mathbf{x}}\Vert}_{2}$ if this is nonzero; otherwise the bound is factor.)*Default*: 100.0$100.0$

- ldfjac

- 1: irevcm – int64int32nag_int scalar
*On intermediate exit*: specifies what action you must take before re-entering nag_roots_withdraw_sys_func_rcomm (c05nd) with irevcm**unchanged**. The value of irevcm should be interpreted as follows:- irevcm = 1 ${\mathbf{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 ${\mathbf{irevcm}}=2$
- Indicates that before re-entry to nag_roots_withdraw_sys_func_rcomm (c05nd), fvec must contain the function values f
_{i}(x) ${f}_{i}\left(x\right)$.

- 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: diag(n) – double array
*On intermediate exit*: the scale factors actually used (computed internally if mode ≠ 2${\mathbf{mode}}\ne 2$).- 5: fjac(ldfjac,n) – double array
- ldfjac ≥ n $\mathit{ldfjac}\ge {\mathbf{n}}$.
*On intermediate exit*: must not be changed.ldfjac ≥ n $\mathit{ldfjac}\ge {\mathbf{n}}$.*On final exit*: the orthogonal matrix Q$Q$ produced by the QR $QR$ factorization of the final approximate Jacobian. - 6: r(n × (n + 1) / 2${\mathbf{n}}\times ({\mathbf{n}}+1)/2$) – double array
*On intermediate exit*: must not be changed.*On final exit*: the upper triangular matrix R$R$ 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 Q^{T}f ${Q}^{\mathrm{T}}f$.- 8: w(n,4$4$) – double array
- 9: ifail – int64int32nag_int scalar
- ifail = 0${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [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.

On entry, n ≤ 0 ${\mathbf{n}}\le 0$, or xtol < 0.0 ${\mathbf{xtol}}<0.0$, or ml < 0 ${\mathbf{ml}}<0$, or mu < 0 ${\mathbf{mu}}<0$, or factor ≤ 0.0 ${\mathbf{factor}}\le 0.0$, or ldfjac < n $\mathit{ldfjac}<{\mathbf{n}}$, or mode = 2 ${\mathbf{mode}}=2$ and diag(i) ≤ 0.0 ${\mathbf{diag}}\left(i\right)\le 0.0$ for some i$i$, i = 1, 2, … , n $i=1,2,\dots ,{\mathbf{n}}$.

On entry, irevcm < 0 ${\mathbf{irevcm}}<0$ or irevcm > 2 ${\mathbf{irevcm}}>2$.

`W`ifail = 3${\mathbf{ifail}}=3$

`W`ifail = 4${\mathbf{ifail}}=4$-
The iteration is not making good progress, as measured by the improvement from the last five Jacobian evaluations.

`W`ifail = 5${\mathbf{ifail}}=5$-
The iteration is not making good progress, as measured by the improvement from the last ten iterations.

A value of ifail = 4${\mathbf{ifail}}={\mathbf{4}}$ or 5${\mathbf{5}}$ 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_rcomm (c05nd) from a different starting point may avoid the region of difficulty.

If
x̂
$\hat{x}$ is the true solution and D$D$ denotes the diagonal matrix whose entries are defined by the array diag, then nag_roots_withdraw_sys_func_rcomm (c05nd) tries to ensure that

If this condition is satisfied with
xtol
=
10^{ − k}
${\mathbf{xtol}}={10}^{-k}$, then the larger components of
Dx
$Dx$ have k$k$ 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_func_rcomm (c05nd) usually obviates this possibility.

$${\Vert D(x-\hat{x})\Vert}_{2}\le {\mathbf{xtol}}\times {\Vert D\hat{x}\Vert}_{2}\text{.}$$ |

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}}$.

The test assumes that the functions are reasonably well behaved. If this condition is not satisfied, then nag_roots_withdraw_sys_func_rcomm (c05nd) may incorrectly indicate convergence. The validity of the answer can be checked, for example, by rerunning nag_roots_withdraw_sys_func_rcomm (c05nd) with a lower value for xtol.

The time required by nag_roots_withdraw_sys_func_rcomm (c05nd) 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_rcomm (c05nd) to process the evaluation of functions in the main program in each exit is about
11.5 × n^{2}
$11.5\times {n}^{2}$. The timing of nag_roots_withdraw_sys_func_rcomm (c05nd) will be strongly influenced by the time spent in the evaluation of the functions.

Ideally the problem should be scaled so that, at the solution, the function values are of comparable magnitude.

The number of function evaluations required to evaluate the Jacobian may be reduced if you can specify ml and mu.

Open in the MATLAB editor: nag_roots_withdraw_sys_func_rcomm_example

function nag_roots_withdraw_sys_func_rcomm_exampleirevcm = int64(0); x = [-1; -1; -1; -1; -1; -1; -1; -1; -1]; fvec = zeros(9,1); ml = int64(1); mu = int64(1); diag = [1; 1; 1; 1; 1; 1; 1; 1; 1]; mode = int64(2); fjac = zeros(9,9); r = zeros(45,1); qtf = zeros(9,1); w = zeros(9, 4); [irevcm, x, fvec, diag, fjac, r, qtt, w, ifail] = ... nag_roots_withdraw_sys_func_rcomm(irevcm, x, fvec, ml, mu, diag, mode, fjac, r, qtf, w); 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, diag, fjac, r, qtf, w, ifail] = ... nag_roots_withdraw_sys_func_rcomm(irevcm, x, fvec, ml, mu, diag, mode, fjac, r, qtf, w); end x

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

Open in the MATLAB editor: c05nd_example

function c05nd_exampleirevcm = int64(0); x = [-1; -1; -1; -1; -1; -1; -1; -1; -1]; fvec = zeros(9,1); ml = int64(1); mu = int64(1); diag = [1; 1; 1; 1; 1; 1; 1; 1; 1]; mode = int64(2); fjac = zeros(9,9); r = zeros(45,1); qtf = zeros(9,1); w = zeros(9, 4); [irevcm, x, fvec, diag, fjac, r, qtt, w, ifail] = ... c05nd(irevcm, x, fvec, ml, mu, diag, mode, fjac, r, qtf, w); 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, diag, fjac, r, qtf, w, ifail] = ... c05nd(irevcm, x, fvec, ml, mu, diag, mode, fjac, r, qtf, w); end x

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

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013