NAG FL Interfacec05mbf (sys_​func_​aa)

1Purpose

c05mbf finds a solution of a system of nonlinear equations by fixed-point iteration using Anderson acceleration.

2Specification

Fortran Interface
 Subroutine c05mbf ( fcn, n, x, fvec, atol, rtol, m,
 Integer, Intent (In) :: n, m, astart Integer, Intent (Inout) :: iuser(*), ifail Real (Kind=nag_wp), Intent (In) :: atol, rtol, cndtol Real (Kind=nag_wp), Intent (Inout) :: x(n), ruser(*) Real (Kind=nag_wp), Intent (Out) :: fvec(n) Type (c_ptr), Intent (In) :: cpuser External :: fcn
#include <nag.h>
 void c05mbf_ (void (NAG_CALL *fcn)(const Integer *n, const double x[], double fvec[], Integer iuser[], double ruser[], void **cpuser, Integer *iflag),const Integer *n, double x[], double fvec[], const double *atol, const double *rtol, const Integer *m, const double *cndtol, const Integer *astart, Integer iuser[], double ruser[], void **cpuser, Integer *ifail)
The routine may be called by the names c05mbf or nagf_roots_sys_func_aa.

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, Anderson acceleration usually results in convergence in far fewer iterations (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$.

4References

Anderson D G (1965) Iterative Procedures for Nonlinear Integral Equations J. Assoc. Comput. Mach. 12 547–560

5Arguments

1: $\mathbf{fcn}$Subroutine, supplied by the user. External Procedure
fcn must return the values of the functions ${f}_{k}$ at a point $x$.
The specification of fcn is:
Fortran Interface
 Subroutine fcn ( n, x, fvec,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: iuser(*), iflag Real (Kind=nag_wp), Intent (In) :: x(n) Real (Kind=nag_wp), Intent (Inout) :: ruser(*) Real (Kind=nag_wp), Intent (Out) :: fvec(n) Type (c_ptr), Intent (In) :: cpuser
 void fcn_ (const Integer *n, const double x[], double fvec[], Integer iuser[], double ruser[], void **cpuser, Integer *iflag)
1: $\mathbf{n}$Integer Input
On entry: $n$, the number of equations.
2: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the components of the point $x$ at which the functions must be evaluated.
3: $\mathbf{fvec}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the function values ${f}_{k}\left(x\right)$ (unless iflag is set to a negative value by fcn).
4: $\mathbf{iuser}\left(*\right)$Integer array User Workspace
5: $\mathbf{ruser}\left(*\right)$Real (Kind=nag_wp) array User Workspace
6: $\mathbf{cpuser}$Type (c_ptr) User Workspace
fcn is called with the arguments iuser, ruser and cpuser as supplied to c05mbf. You should use the arrays iuser and ruser, and the data handle cpuser to supply information to fcn.
7: $\mathbf{iflag}$Integer Input/Output
On entry: ${\mathbf{iflag}}\ge 0$.
On exit: 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), iflag should be set to a negative integer. This value will be returned through ifail.
fcn must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which c05mbf is called. Arguments denoted as Input must not be changed by this procedure.
Note: fcn should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by c05mbf. If your code inadvertently does return any NaNs or infinities, c05mbf 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 entry: an initial guess at the solution vector, ${\stackrel{^}{x}}_{0}$.
On exit: the final estimate of the solution vector.
4: $\mathbf{fvec}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the function values at the final point, x.
5: $\mathbf{atol}$Real (Kind=nag_wp) Input
On entry: the absolute convergence criterion; see rtol.
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 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 x02ajf.
Constraint: ${\mathbf{rtol}}\ge 0.0$.
7: $\mathbf{m}$Integer Input
On 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 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 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{iuser}\left(*\right)$Integer array User Workspace
11: $\mathbf{ruser}\left(*\right)$Real (Kind=nag_wp) array User Workspace
12: $\mathbf{cpuser}$Type (c_ptr) User Workspace
iuser, ruser and cpuser are not used by c05mbf, but are passed directly to fcn and may be used to pass information to this routine. If you do not need to reference cpuser, it should be initialized to c_null_ptr.
13: $\mathbf{ifail}$Integer Input/Output
On 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 $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

6Error 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 entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}>0$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{atol}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{atol}}\ge 0.0$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{rtol}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{rtol}}\ge 0.0$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: $0\le {\mathbf{m}}\le {\mathbf{n}}$.
${\mathbf{ifail}}=5$
On entry, ${\mathbf{cndtol}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{cndtol}}\ge 0.0$.
${\mathbf{ifail}}=6$
On entry, ${\mathbf{astart}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{astart}}\ge 0$.
${\mathbf{ifail}}=7$
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}}=8$
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. Rerunning c05mbf from a different starting point may avoid the region of difficulty.
${\mathbf{ifail}}=9$
There have been at least $200×\left({\mathbf{n}}+1\right)$ calls to fcn. Consider restarting the calculation from the point held in x.
${\mathbf{ifail}}=10$
Termination requested in fcn.
${\mathbf{ifail}}=11$
The iteration has diverged and subsequent iterates are too large to be computed in floating-point arithmetic.
${\mathbf{ifail}}=-99$
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.

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, c05mbf 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 exit from c05mbf.

8Parallelism and Performance

c05mbf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
c05mbf 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 implementation-specific 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)$ floating-point operations per iteration compared with the unaccelerated fixed-point iteration.
c05mdf also performs a fixed-point iteration with Anderson acceleration. It has a reverse communication interface, so may be preferred to c05mbf when function evaluations are difficult to encapsulate in a routine argument.

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 (c05mbfe.f90)

None.

10.3Program Results

Program Results (c05mbfe.r)