NAG FL Interface
c05mdf (sys_func_aa_rcomm)
1
Purpose
c05mdf is a comprehensive reverse communication routine that finds a solution of a system of nonlinear equations by fixedpoint iteration using Anderson acceleration.
2
Specification
Fortran Interface
Subroutine c05mdf ( 
irevcm, n, x, fvec, atol, rtol, m, cndtol, astart, iwsav, rwsav, ifail) 
Integer, Intent (In) 
:: 
n, m, astart 
Integer, Intent (Inout) 
:: 
irevcm, iwsav(14+m), ifail 
Real (Kind=nag_wp), Intent (In) 
:: 
atol, rtol, cndtol 
Real (Kind=nag_wp), Intent (Inout) 
:: 
x(n), fvec(n), rwsav(2*m*n+m*m+m+2*n+1+min(m,1)*max(n,3*m)) 

C Header Interface
#include <nag.h>
void 
c05mdf_ (Integer *irevcm, const Integer *n, double x[], double fvec[], const double *atol, const double *rtol, const Integer *m, const double *cndtol, const Integer *astart, Integer iwsav[], double rwsav[], Integer *ifail) 

C++ Header Interface
#include <nag.h> extern "C" {
void 
c05mdf_ (Integer &irevcm, const Integer &n, double x[], double fvec[], const double &atol, const double &rtol, const Integer &m, const double &cndtol, const Integer &astart, Integer iwsav[], double rwsav[], Integer &ifail) 
}

The routine may be called by the names c05mdf or nagf_roots_sys_func_aa_rcomm.
3
Description
The system of equations is defined as:
This homogeneous system can readily be reformulated as
A standard fixedpoint iteration approach is to start with an approximate solution
${\hat{x}}_{0}$ and repeatedly apply the function
$g$ until possible convergence; i.e.,
${\hat{x}}_{i+1}=g\left({\hat{x}}_{i}\right)$, until
$\Vert {\hat{x}}_{i+1}{\hat{x}}_{i}\Vert <\text{tol}$. Anderson acceleration uses up to
$m$ previous values of
$\hat{x}$ to obtain an improved estimate
${\hat{x}}_{i+1}$. If a standard fixedpoint 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$.
4
References
Anderson D G (1965) Iterative Procedures for Nonlinear Integral Equations J. Assoc. Comput. Mach. 12 547–560
5
Arguments
Note: this routine uses
reverse communication. Its use involves an initial entry, intermediate exits and reentries, and a final exit, as indicated by the argument
irevcm. Between intermediate exits and reentries,
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 reentering
c05mdf 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 reentry to c05mdf, fvec must contain the function values $f\left({\hat{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 c05mdf as part of the reverse communication procedure should not include floatingpoint NaN (Not a Number) or infinity values, since these are not handled by c05mdf. If your code does inadvertently return any NaNs or infinities, c05mdf is likely to produce unexpected results.

2:
$\mathbf{n}$ – Integer
Input

On entry: $n$, the number of equations.
Constraint:
${\mathbf{n}}>0$.

3:
$\mathbf{x}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) array
Input/Output

On initial entry: an initial guess at the solution vector, ${\hat{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)$ – Real (Kind=nag_wp) array
Input/Output

On initial entry: need not be set.
On intermediate reentry: 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({\hat{x}}_{i}\right)$.
On final exit: the function values at the final point,
x.

5:
$\mathbf{atol}$ – Real (Kind=nag_wp)
Input

On initial entry: the absolute convergence criterion; see below.
Suggested value:
$\sqrt{\epsilon}$, where
$\epsilon $ is the
machine precision returned by
x02ajf.
Constraint:
${\mathbf{atol}}\ge 0.0$.

6:
$\mathbf{rtol}$ – Real (Kind=nag_wp)
Input

On initial entry: the relative convergence criterion. At each iteration $\Vert f\left({\hat{x}}_{i}\right)\Vert $ is computed. The iteration is deemed to have converged if $\Vert f\left({\hat{x}}_{i}\right)\Vert \le \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{atol}},{\mathbf{rtol}}\times \Vert f\left({\hat{x}}_{0}\right)\Vert \right)$.
Suggested value:
$\sqrt{\epsilon}$, where
$\epsilon $ is the
machine precision returned by
x02ajf.
Constraint:
${\mathbf{rtol}}\ge 0.0$.

7:
$\mathbf{m}$ – Integer
Input

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}$ – Real (Kind=nag_wp)
Input

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}$ – Integer
Input

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)$ – Integer array
Communication Array

11:
$\mathbf{rwsav}\left(2\times {\mathbf{m}}\times {\mathbf{n}}+{{\mathbf{m}}}^{2}+{\mathbf{m}}+2\times {\mathbf{n}}+1+\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{m}},1\right)\times \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n}},3\times {\mathbf{m}}\right)\right)$ – Real (Kind=nag_wp) array
Communication Array

The arrays
iwsav and
rwsav must not be altered between calls to
c05mdf.
The size of
rwsav is bounded above by
$3\times {\mathbf{n}}\times \left({\mathbf{m}}+2\right)+1$.

12:
$\mathbf{ifail}$ – Integer
Input/Output

On initial entry:
ifail must be set to
$0$,
$1$ or
$1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value
$1$ or
$1$ is recommended. If message printing is undesirable, then the value
$1$ is recommended. Otherwise, the value
$1$ is recommended since useful values can be provided in some output arguments even when
${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit.
When the value $\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On final exit:
${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
${\mathbf{ifail}}=0$ or
$1$, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
 ${\mathbf{ifail}}=1$

On initial entry, ${\mathbf{irevcm}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{irevcm}}=0$.
On intermediate entry, ${\mathbf{irevcm}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{irevcm}}=1$ or $2$.
 ${\mathbf{ifail}}=2$

On entry, ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{n}}>0$.
 ${\mathbf{ifail}}=3$

On entry, ${\mathbf{atol}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{atol}}\ge 0.0$.
 ${\mathbf{ifail}}=4$

On entry, ${\mathbf{rtol}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{rtol}}\ge 0.0$.
 ${\mathbf{ifail}}=5$

On entry, ${\mathbf{m}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: $0\le {\mathbf{m}}\le {\mathbf{n}}$.
 ${\mathbf{ifail}}=6$

On entry, ${\mathbf{cndtol}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{cndtol}}\ge 0.0$.
 ${\mathbf{ifail}}=7$

On entry, ${\mathbf{astart}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{astart}}\ge 0$.
 ${\mathbf{ifail}}=8$

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.
 ${\mathbf{ifail}}=9$

The iteration is not making good progress, as measured by the reduction in the norm of $f\left(x\right)$ in the last $\u2329\mathit{\text{value}}\u232a$ iterations.
 ${\mathbf{ifail}}=10$

The iteration has diverged and subsequent iterates are too large to be computed in floatingpoint arithmetic.
 ${\mathbf{ifail}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
 ${\mathbf{ifail}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
 ${\mathbf{ifail}}=999$
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
Accuracy
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 fixedpoint methods (which may only converge linearly), and in some cases can even alleviate divergence.
At each iteration,
c05mdf checks whether
$\Vert f\left({\hat{x}}_{i}\right)\Vert \le \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{atol}},{\mathbf{rtol}}\times \Vert f\left({\hat{x}}_{0}\right)\Vert \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
c05mdf.
8
Parallelism and Performance
c05mdf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
c05mdf 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 routine. Please also consult the
Users' Note for your implementation for any additional implementationspecific information.
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)$ floatingpoint operations per iteration compared with the unaccelerated fixedpoint iteration.
c05mdf 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 c05mdf is called. This is illustrated in the example program below.
10
Example
This example determines the values
${x}_{1},\dots ,{x}_{4}$ which satisfy the equations
10.1
Program Text
10.2
Program Data
None.
10.3
Program Results