# NAG AD Library Routine Document

## e04fc_a1w_f (lsq_uncon_mod_func_comp_a1w)

Note: _a1w_ denotes that first order adjoints are computed in working precision; this has the corresponding argument type nagad_a1w_w_rtype. Further implementations, for example for higher order differentiation or using the tangent linear approach, may become available at later marks of the NAG AD Library. The method of codifying AD implementations in routine name and corresponding argument types is described in the NAG AD Library Introduction.

## 1Purpose

e04fc_a1w_f is the adjoint version of the primal routine e04fcf .

## 2Specification

Fortran Interface
 Subroutine e04fc_a1w_f ( ad_handle, m, n, lsqfun, lsqmon, iprint, maxcal, eta, xtol, stepmx, x, fsumsq, fvec, fjac, ldfjac, s, v, ldv, niter, nf, iuser, ruser, ifail)
 Integer, Intent (In) :: m, n, iprint, maxcal, ldfjac, ldv Integer, Intent (Inout) :: iuser(*), ifail Integer, Intent (Out) :: niter, nf Type (nagad_a1w_w_rtype), Intent (In) :: eta, xtol, stepmx Type (nagad_a1w_w_rtype), Intent (Inout) :: x(n), fjac(ldfjac,n), v(ldv,n), ruser(*) Type (nagad_a1w_w_rtype), Intent (Out) :: fsumsq, fvec(m), s(n) Type (c_ptr), Intent (In) :: ad_handle External :: lsqfun, lsqmon
 Subroutine lsqfun ( ad_handle, iflag, m, n, xc, fvec, iuser, ruser)
 Integer, Intent (In) :: m, n Integer, Intent (Inout) :: iflag, iuser(*) Type (nagad_a1w_w_rtype), Intent (Inout) :: xc(n), ruser(*), fvec(m) Type (c_ptr), Intent (In) :: ad_handle
 Subroutine lsqmon ( ad_handle, m, n, xc, fvec, fjac, ldfjac, s, igrade, niter, nf, iuser, ruser)
 Integer, Intent (In) :: m, n, ldfjac, igrade, niter, nf Integer, Intent (Inout) :: iuser(*) Type (nagad_a1w_w_rtype), Intent (Inout) :: xc(n), fvec(m), fjac(ldfjac,n), s(n), ruser(*) Type (c_ptr), Intent (In) :: ad_handle

## 3Description

e04fcf is a comprehensive algorithm for finding an unconstrained minimum of a sum of squares of $m$ nonlinear functions in $n$ variables $\left(m\ge n\right)$. No derivatives are required.
The routine is intended for functions which have continuous first and second derivatives (although it will usually work even if the derivatives have occasional discontinuities). For further information see Section 3 in the documentation for e04fcf .

None.

## 5Arguments

e04fc_a1w_f provides access to all the arguments available in the primal routine. There are also additional arguments specific to AD. A tooltip popup for each argument can be found by hovering over the argument name in Section 2 and a summary of the arguments are provided below:
• ad_handle – a handle to the AD configuration data object, as created by x10aa_a1w_f.
• m – the number $m$ of residuals, ${f}_{i}\left(x\right)$, and the number $n$ of variables, ${x}_{j}$.
• n – the number $m$ of residuals, ${f}_{i}\left(x\right)$, and the number $n$ of variables, ${x}_{j}$.
• lsqfunlsqfun must calculate the vector of values ${f}_{i}\left(x\right)$ at any point $x$.
• lsqmon – If $\mathbf{iprint}\ge \mathrm{0}$, you must supply lsqmon which is suitable for monitoring the minimization process.
• iprint – the frequency with which lsqmon is to be called.
• maxcal – the limit you set on the number of times that lsqfun may be called by routine.
• eta – specifies how accurately the linear minimizations are to be performed.
• xtol – the accuracy in $x$ to which the solution is required.
• stepmx – an estimate of the Euclidean distance between the solution and the starting point supplied by you.
• x – on entry: $\mathbf{x}\left(\mathit{j}\right)$ must be set to a guess at the $\mathit{j}$th component of the position of the minimum, for $\mathit{j}=\mathrm{1},2, \dots ,n$. on exit: the final point ${x}^{\left(k\right)}$.
• fsumsq – on exit: the value of $F\left(x\right)$, the sum of squares of the residuals ${f}_{i}\left(x\right)$, at the final point given in x.
• fvec – on exit: the value of the residual ${f}_{\mathit{i}}\left(x\right)$ at the final point given in x, for $\mathit{i}=\mathrm{1},2, \dots ,m$.
• fjac – on exit: the estimate of the first derivative $\frac{\partial {f}_{\mathit{i}}}{\partial {x}_{\mathit{j}}}$ at the final point given in x, for $\mathit{j}=\mathrm{1},2, \dots ,n$, for $\mathit{i}=\mathrm{1},2, \dots ,m$.
• ldfjac – the first dimension of the array fjac.
• s – on exit: the singular values of the estimated Jacobian matrix at the final point.
• v – on exit: the matrix $V$ associated with the singular value decomposition. $J=US{V}^{T}$. of the estimated Jacobian matrix at the final point, stored by columns.
• ldv – the first dimension of the array v.
• niter – on exit: the number of iterations which have been performed in routine.
• nf – on exit: the number of times that the residuals have been evaluated (i.e., number of calls of lsqfun).
• iuser – may be used to pass information to user-supplied argument(s).
• ruser – may be used to pass information to user-supplied argument(s).
• ifail – on entry: ifail must be set to $\mathrm{0}$, $-\mathrm{1}\text{ or }\mathrm{1}$. on exit: ifail = 0 unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

e04fc_a1w_f preserves all error codes from e04fcf and in addition can return:
$\mathbf{ifail}=-89$
See Section 5.2 in the NAG AD Library Introduction for further information.
$\mathbf{ifail}=-899$
Dynamic memory allocation failed for AD.
See Section 5.1 in the NAG AD Library Introduction for further information.

Not applicable.

## 8Parallelism and Performance

e04fc_a1w_f is not threaded in any implementation.