# NAG CPP Interfacenagcpp::opt::handle_set_nlnls (e04rm)

## 1Purpose

handle_set_nlnls is a part of the NAG optimization modelling suite and defines the number of residuals in a sum of squares objective function (nonlinear least squares problems) and, optionally, the sparsity structure of their first derivatives.

## 2Specification

```#include "e04/nagcpp_e04rm.hpp"
#include "e04/nagcpp_class_CommE04RA.hpp"
```
```template <typename COMM, typename IROWRD, typename ICOLRD>

void function handle_set_nlnls(COMM &comm, const types::f77_integer nres, const IROWRD &irowrd, const ICOLRD &icolrd, OptionalE04RM opt)```
```template <typename COMM, typename IROWRD, typename ICOLRD>

void function handle_set_nlnls(COMM &comm, const types::f77_integer nres, const IROWRD &irowrd, const ICOLRD &icolrd)```

## 3Description

After the initialization function handle_​init has been called and unless the objective function has already been defined, handle_set_nlnls may be used to declare the objective function of the optimization problem as a sum of squares. It will typically be used in data fitting or calibration problems of the form
 $minimize x∈ℝn f(x)= ∑ j=1 mr rj (x) 2 subject to lx≤x≤ux ,$
where $x$ is an $n$-dimensional variable vector and ${r}_{i}\left(x\right)$ are nonlinear residuals (see Section 2.2.3 in the E04 Chapter Introduction). The values of the residuals, and possibly their derivatives, will be communicated to the solver by a user-supplied function. handle_set_nlnls also allows the structured first derivative matrix
 $[ ∂rj(x) ∂xi ] i=1,…,n , ​ j=1,…,mr$
to be declared as being dense or sparse. If declared as sparse, its sparsity structure must be specified here.
See Section 3.1 in the E04 Chapter Introduction for more details about the NAG optimization modelling suite.
None.

## 5Arguments

1: $\mathbf{comm}$CommE04RA Input/Output
Communication structure. An object of either the derived class CommE04RA or its base class NoneCopyableComm can be supplied. It is recommended that the derived class is used. If the base class is supplied it must first be initialized via a call to opt::handle_init (e04ra).
2: $\mathbf{nres}$types::f77_integer Input
On entry: ${m}_{r}$, the number of residuals in the objective function.
If ${\mathbf{nres}}=0$, no objective function will be defined and irowrd and icolrd will not be referenced.
Constraint: ${\mathbf{nres}}\ge 0$.
3: $\mathbf{irowrd}\left({\mathbf{nnzrd}}\right)$types::f77_integer array Input
On entry: arrays irowrd and icolrd store the sparsity structure (pattern) of the first derivative matrix as nnzrd nonzeros in coordinate storage (CS) format (see Section 2.1.1 in the F11 Chapter Introduction). The matrix has dimensions $n×{m}_{r}$. irowrd specifies one-based row indices and icolrd specifies one-based column indices. No particular order of elements is expected, but elements should not repeat and the same order should be used when the first derivative matrix is evaluated for the solver.
If irowrd and icolrd are both nullptr then the first derivative matrix is considered dense and irowrd and icolrd will not be referenced. The ordering is assumed to be column-wise, namely the function will behave as if ${\mathbf{nnzrd}}=n×{m}_{r}$ and the vectors irowrd and icolrd filled as:
• ${\mathbf{irowrd}}=\left(1,2,\dots ,n,1,2,\dots ,n,\dots ,1,2,\dots ,n\right)$;
• ${\mathbf{icolrd}}=\left(1,1,\dots ,1,2,2,\dots ,2,\dots ,{m}_{r},{m}_{r},\dots ,{m}_{r}\right)$.
Constraints:
• $1\le {\mathbf{irowrd}}\left(\mathit{l}-1\right)\le n$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzrd}}$;
• $1\le {\mathbf{icolrd}}\left(\mathit{l}-1\right)\le {\mathbf{nres}}$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzrd}}$.
4: $\mathbf{icolrd}\left({\mathbf{nnzrd}}\right)$types::f77_integer array Input
On entry: arrays irowrd and icolrd store the sparsity structure (pattern) of the first derivative matrix as nnzrd nonzeros in coordinate storage (CS) format (see Section 2.1.1 in the F11 Chapter Introduction). The matrix has dimensions $n×{m}_{r}$. irowrd specifies one-based row indices and icolrd specifies one-based column indices. No particular order of elements is expected, but elements should not repeat and the same order should be used when the first derivative matrix is evaluated for the solver.
If irowrd and icolrd are both nullptr then the first derivative matrix is considered dense and irowrd and icolrd will not be referenced. The ordering is assumed to be column-wise, namely the function will behave as if ${\mathbf{nnzrd}}=n×{m}_{r}$ and the vectors irowrd and icolrd filled as:
• ${\mathbf{irowrd}}=\left(1,2,\dots ,n,1,2,\dots ,n,\dots ,1,2,\dots ,n\right)$;
• ${\mathbf{icolrd}}=\left(1,1,\dots ,1,2,2,\dots ,2,\dots ,{m}_{r},{m}_{r},\dots ,{m}_{r}\right)$.
Constraints:
• $1\le {\mathbf{irowrd}}\left(\mathit{l}-1\right)\le n$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzrd}}$;
• $1\le {\mathbf{icolrd}}\left(\mathit{l}-1\right)\le {\mathbf{nres}}$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzrd}}$.
5: $\mathbf{opt}$OptionalE04RM Input/Output
Optional parameter container, derived from Optional.

1: $\mathbf{nnzrd}$
The number of nonzeros in the first derivative matrix.

## 6Exceptions and Warnings

Errors or warnings detected by the function:
All errors and warnings have an associated numeric error code field, errorid, stored either as a member of the thrown exception object (see errorid), or as a member of opt.ifail, depending on how errors and warnings are being handled (see Error Handling for more details).
Raises: ErrorException
$\mathbf{errorid}=9$
All of the following must be provided if one is provided:
irowrd, icolrd.
$\mathbf{errorid}=1$
comm::handle has not been initialized.
$\mathbf{errorid}=1$
comm::handle does not belong to the NAG optimization modelling suite,
has not been initialized properly or is corrupted.
$\mathbf{errorid}=1$
comm::handle has not been initialized properly or is corrupted.
$\mathbf{errorid}=2$
The problem cannot be modified in this phase any more, the solver
$\mathbf{errorid}=2$
The Hessians of nonlinear functions have already been defined,
a nonlinear objective cannot be added.
$\mathbf{errorid}=3$
The objective function has already been defined.
$\mathbf{errorid}=6$
On entry, ${\mathbf{nres}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{nres}}\ge 0$.
$\mathbf{errorid}=6$
On entry, ${\mathbf{nnzrd}}=⟨\mathit{value}⟩$.
Constraint: ${\mathbf{nnzrd}}>0$.
$\mathbf{errorid}=8$
On entry, $i=⟨\mathit{value}⟩$, ${\mathbf{irowrd}}\left[i-1\right]=⟨\mathit{value}⟩$ and
$n=⟨\mathit{value}⟩$.
Constraint: $1\le {\mathbf{irowrd}}\left[i-1\right]\le n$.
$\mathbf{errorid}=8$
On entry, $i=⟨\mathit{value}⟩$, ${\mathbf{icolrd}}\left[i-1\right]=⟨\mathit{value}⟩$ and
${\mathbf{nres}}=⟨\mathit{value}⟩$.
Constraint: $1\le {\mathbf{icolrd}}\left[i-1\right]\le {\mathbf{nres}}$.
$\mathbf{errorid}=8$
On entry, more than one element of first derivative matrix has row index
$⟨\mathit{\text{value}}⟩$ and column index $⟨\mathit{\text{value}}⟩$.
Constraint: each element of first derivative matrix must have a unique
row and column index.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
Supplied argument has $⟨\mathit{\text{value}}⟩$ dimensions.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
Supplied argument was a vector of size $⟨\mathit{\text{value}}⟩$.
$\mathbf{errorid}=10601$
On entry, argument $⟨\mathit{\text{value}}⟩$ must be a vector of size $⟨\mathit{\text{value}}⟩$ array.
The size for the supplied array could not be ascertained.
$\mathbf{errorid}=10602$
On entry, the raw data component of $⟨\mathit{\text{value}}⟩$ is null.
$\mathbf{errorid}=10603$
On entry, unable to ascertain a value for $⟨\mathit{\text{value}}⟩$.
$\mathbf{errorid}=10605$
On entry, the communication class $⟨\mathit{\text{value}}⟩$ has not been initialized correctly.
$\mathbf{errorid}=-99$
An unexpected error has been triggered by this routine.
$\mathbf{errorid}=-399$
Your licence key may have expired or may not have been installed correctly.
$\mathbf{errorid}=-999$
Dynamic memory allocation failed.

Not applicable.

## 8Parallelism and Performance

Please see the description for the underlying computational routine in this section of the FL Interface documentation.