# NAG C Library Function Document

## 1Purpose

nag_zero_nonlin_eqns_aa_rcomm (c05mdc) is a comprehensive reverse communication function that finds a solution of a system of nonlinear equations by fixed-point iteration using Anderson acceleration.

## 2Specification

 #include #include
 void nag_zero_nonlin_eqns_aa_rcomm (Integer *irevcm, Integer n, double x[], double fvec[], double atol, double rtol, Integer m, double cndtol, Integer astart, Integer iwsav[], double rwsav[], NagError *fail)

## 3Description

The system of equations is defined as:
 $fk x1,x2,…,xn = 0 , k= 1, 2, …, n .$
This homogeneous system can readily be reformulated as
 $gx=x, x∈ℝn.$
A standard fixed-point iteration approach is to start with an approximate solution ${\stackrel{^}{x}}_{0}$ and repeatedly apply the function $g$ until possible convergence; i.e., ${\stackrel{^}{x}}_{i+1}=g\left({\stackrel{^}{x}}_{i}\right)$, until $‖{\stackrel{^}{x}}_{i+1}-{\stackrel{^}{x}}_{i}‖<\text{tol}$. Anderson acceleration uses up to $m$ previous values of $\stackrel{^}{x}$ to obtain an improved estimate ${\stackrel{^}{x}}_{i+1}$. If a standard fixed-point iteration converges, then Anderson acceleration usually results in convergence in far fewer iterations (and therefore using far fewer function evaluations).
Full details of Anderson acceleration are provided in Anderson (1965). In summary, the previous $m$ iterates are combined to form a succession of least squares problems. These are solved using a QR decomposition, which is updated at each iteration.
You are free to choose any value for $m$, provided $m\le n$. A typical choice is $m=4$.
Anderson D G (1965) Iterative Procedures for Nonlinear Integral Equations J. Assoc. Comput. Mach. 12 547–560

## 5Arguments

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 must remain unchanged.
1:    $\mathbf{irevcm}$Integer *Input/Output
On initial entry: must have the value $0$.
On intermediate exit: specifies what action you must take before re-entering nag_zero_nonlin_eqns_aa_rcomm (c05mdc) with irevcm unchanged. The value of irevcm should be interpreted as follows:
${\mathbf{irevcm}}=1$
Indicates the start of a new iteration. No action is required by you, but x and fvec are available for printing, and a limit on the number of iterations can be applied.
${\mathbf{irevcm}}=2$
Indicates that before re-entry to nag_zero_nonlin_eqns_aa_rcomm (c05mdc), fvec must contain the function values $f\left({\stackrel{^}{x}}_{i}\right)$.
On final exit: ${\mathbf{irevcm}}=0$ and the algorithm has terminated.
Constraint: ${\mathbf{irevcm}}=0$, $1$ or $2$.
Note: any values you return to nag_zero_nonlin_eqns_aa_rcomm (c05mdc) as part of the reverse communication procedure should not include floating-point NaN (Not a Number) or infinity values, since these are not handled by nag_zero_nonlin_eqns_aa_rcomm (c05mdc). If your code inadvertently does return any NaNs or infinities, nag_zero_nonlin_eqns_aa_rcomm (c05mdc) is likely to produce unexpected results.
2:    $\mathbf{n}$IntegerInput
On entry: $n$, the number of equations.
Constraint: ${\mathbf{n}}>0$.
3:    $\mathbf{x}\left[{\mathbf{n}}\right]$doubleInput/Output
On initial entry: an initial guess at the solution vector, ${\stackrel{^}{x}}_{0}$.
On intermediate exit: contains the current point.
On final exit: the final estimate of the solution vector.
4:    $\mathbf{fvec}\left[{\mathbf{n}}\right]$doubleInput/Output
On initial entry: need not be set.
On intermediate re-entry: if ${\mathbf{irevcm}}=1$, fvec must not be changed.
If ${\mathbf{irevcm}}=2$, fvec must be set to the values of the functions computed at the current point x, $f\left({\stackrel{^}{x}}_{i}\right)$.
On final exit: the function values at the final point, x.
5:    $\mathbf{atol}$doubleInput
On initial entry: the absolute convergence criterion; see below.
Suggested value: $\sqrt{\epsilon }$, where $\epsilon$ is the machine precision returned by nag_machine_precision (X02AJC).
Constraint: ${\mathbf{atol}}\ge 0.0$.
6:    $\mathbf{rtol}$doubleInput
On initial entry: the relative convergence criterion. At each iteration $‖f\left({\stackrel{^}{x}}_{i}\right)‖$ is computed. The iteration is deemed to have converged if $‖f\left({\stackrel{^}{x}}_{i}\right)‖\le \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{atol}},{\mathbf{rtol}}×‖f\left({\stackrel{^}{x}}_{0}\right)‖\right)$.
Suggested value: $\sqrt{\epsilon }$, where $\epsilon$ is the machine precision returned by nag_machine_precision (X02AJC).
Constraint: ${\mathbf{rtol}}\ge 0.0$.
7:    $\mathbf{m}$IntegerInput
On initial entry: $m$, the number of previous iterates to use in Anderson acceleration. If $m=0$, Anderson acceleration is not used.
Suggested value: ${\mathbf{m}}=4$.
Constraint: $0\le {\mathbf{m}}\le {\mathbf{n}}$.
8:    $\mathbf{cndtol}$doubleInput
On initial entry: the maximum allowable condition number for the triangular QR factor generated during Anderson acceleration. At each iteration, if the condition number exceeds cndtol, columns are deleted until it is sufficiently small.
If ${\mathbf{cndtol}}=0.0$, no condition number tests are performed.
Suggested value: ${\mathbf{cndtol}}=0.0$. If condition number tests are required, a suggested value is ${\mathbf{cndtol}}=1.0/\sqrt{\epsilon }$.
Constraint: ${\mathbf{cndtol}}\ge 0.0$.
9:    $\mathbf{astart}$IntegerInput
On initial entry: the number of iterations by which to delay the start of Anderson acceleration.
Suggested value: ${\mathbf{astart}}=0$.
Constraint: ${\mathbf{astart}}\ge 0$.
10:  $\mathbf{iwsav}\left[14+{\mathbf{m}}\right]$IntegerCommunication Array
11:  $\mathbf{rwsav}\left[2×{\mathbf{m}}×{\mathbf{n}}+{{\mathbf{m}}}^{2}+{\mathbf{m}}+2×{\mathbf{n}}+1+\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}},1\right)×\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}},3×{\mathbf{m}}\right)\right]$doubleCommunication Array
The arrays iwsav and rwsav MUST NOT be altered between calls to nag_zero_nonlin_eqns_aa_rcomm (c05mdc).
The size of rwsav is bounded above by $3×{\mathbf{n}}×\left({\mathbf{m}}+2\right)+1$.
12:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_BAD_PARAM
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_CONVERGENCE
An error occurred in evaluating the QR decomposition during Anderson acceleration. This may be due to slow convergence of the iteration. Try setting the value of cndtol. If condition number tests are already performed, try decreasing cndtol.
NE_INT
On entry, ${\mathbf{astart}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{astart}}\ge 0$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}>0$.
On initial entry, ${\mathbf{irevcm}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{irevcm}}=0$.
On intermediate entry, ${\mathbf{irevcm}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{irevcm}}=1$ or $2$.
NE_INT_2
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: $0\le {\mathbf{m}}\le {\mathbf{n}}$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_IMPROVEMENT
The iteration is not making good progress, as measured by the reduction in the norm of $f\left(x\right)$ in the last $〈\mathit{\text{value}}〉$ iterations.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_REAL
On entry, ${\mathbf{atol}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{atol}}\ge 0.0$.
On entry, ${\mathbf{cndtol}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{cndtol}}\ge 0.0$.
On entry, ${\mathbf{rtol}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{rtol}}\ge 0.0$.

## 7Accuracy

There are no theoretical guarantees of global or local convergence for Anderson acceleration. However, extensive numerical tests show that, in practice, Anderson acceleration leads to significant improvements over the underlying fixed-point methods (which may only converge linearly), and in some cases can even alleviate divergence.
At each iteration, nag_zero_nonlin_eqns_aa_rcomm (c05mdc) checks whether $‖f\left({\stackrel{^}{x}}_{i}\right)‖\le \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{atol}},{\mathbf{rtol}}×‖f\left({\stackrel{^}{x}}_{0}\right)‖\right)$. If the inequality is satisfied, then the iteration is deemed to have converged. The validity of the answer may be checked by inspecting the value of fvec on final exit from nag_zero_nonlin_eqns_aa_rcomm (c05mdc).

## 8Parallelism and Performance

nag_zero_nonlin_eqns_aa_rcomm (c05mdc) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

## 9Further Comments

During each iteration, Anderson acceleration updates the factors of a QR decomposition and uses the decomposition to solve a linear least squares problem. This involves an additional $\mathit{O}\left(mn\right)$ floating-point operations per iteration compared with the unaccelerated fixed-point iteration.
nag_zero_nonlin_eqns_aa_rcomm (c05mdc) does not count the number of iterations. Thus, it is up to you to add a limit on the number of iterations and check if this limit has been exceeded when nag_zero_nonlin_eqns_aa_rcomm (c05mdc) is called. This is illustrated in the example program below.

## 10Example

This example determines the values ${x}_{1},\dots ,{x}_{4}$ which satisfy the equations
 $cos⁡x3-x1 = 0, 1-x42-x2 = 0, sin⁡x1-x3 = 0, x22-x4 = 0.$

### 10.1Program Text

Program Text (c05mdce.c)

None.

### 10.3Program Results

Program Results (c05mdce.r)