# NAG FL Interfacee04rmf (handle_​set_​nlnls)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

e04rmf is a part of the NAG optimization modelling suite and declares the objective function of the problem as a sum of squares (for nonlinear least squares problems) with the given number of residuals and, optionally, the sparsity structure of their first derivatives.

## 2Specification

Fortran Interface
 Subroutine e04rmf ( nres,
 Integer, Intent (In) :: nres, isparse, nnzrd, irowrd(nnzrd), icolrd(nnzrd) Integer, Intent (Inout) :: ifail Type (c_ptr), Intent (In) :: handle
#include <nag.h>
 void e04rmf_ (void **handle, const Integer *nres, const Integer *isparse, const Integer *nnzrd, const Integer irowrd[], const Integer icolrd[], Integer *ifail)
The routine may be called by the names e04rmf or nagf_opt_handle_set_nlnls.

## 3Description

After the handle has been initialized (e.g., e04raf has been called), e04rmf may be used to declare the objective function of the optimization problem as a sum of squares. If the objective function has already been defined, it will be overwritten. 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}_{j}\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. e04rmf 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 by e04rmf. If e04rmf is called with ${m}_{r}=0$, any existing objective function is removed, no new one is added and the problem will be solved as a feasible point problem. Note that it is possible to temporarily disable and enable individual residuals in the model by e04tcf and e04tbf, respectively.
See Section 3.1 in the E04 Chapter Introduction for more details about the NAG optimization modelling suite.

None.

## 5Arguments

1: $\mathbf{handle}$Type (c_ptr) Input
On entry: the handle to the problem. It needs to be initialized (e.g., by e04raf) and must not be changed between calls to the NAG optimization modelling suite.
2: $\mathbf{nres}$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{isparse}$Integer Input
On entry: is a flag indicating if the nonzero structure of the first derivative matrix is dense or sparse.
${\mathbf{isparse}}=0$
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 routine 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)$.
${\mathbf{isparse}}=1$
The sparsity structure of the first derivative matrix will be supplied by nnzrd, irowrd and icolrd.
Constraint: ${\mathbf{isparse}}=0$ or $1$.
4: $\mathbf{nnzrd}$Integer Input
On entry: the number of nonzeros in the first derivative matrix.
Constraint: if ${\mathbf{isparse}}=1$ and ${\mathbf{nres}}>0$, ${\mathbf{nnzrd}}>0$.
5: $\mathbf{irowrd}\left({\mathbf{nnzrd}}\right)$Integer array Input
6: $\mathbf{icolrd}\left({\mathbf{nnzrd}}\right)$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.
Constraints:
• $1\le {\mathbf{irowrd}}\left(\mathit{l}\right)\le n$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzrd}}$;
• $1\le {\mathbf{icolrd}}\left(\mathit{l}\right)\le {\mathbf{nres}}$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzrd}}$.
7: $\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 $-1$ 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$
The supplied handle does not define a valid handle to the data structure for the NAG optimization modelling suite. It has not been properly initialized or it has been corrupted.
${\mathbf{ifail}}=2$
The problem cannot be modified right now, the solver is running.
${\mathbf{ifail}}=6$
On entry, ${\mathbf{isparse}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{isparse}}=0$ or $1$.
On entry, ${\mathbf{nnzrd}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nnzrd}}>0$.
On entry, ${\mathbf{nres}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nres}}\ge 0$.
${\mathbf{ifail}}=8$
On entry, $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{icolrd}}\left(\mathit{i}\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{nres}}=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{icolrd}}\left(\mathit{i}\right)\le {\mathbf{nres}}$.
On entry, $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{irowrd}}\left(\mathit{i}\right)=⟨\mathit{\text{value}}⟩$ and $n=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{irowrd}}\left(\mathit{i}\right)\le n$.
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{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.

Not applicable.

## 8Parallelism and Performance

e04rmf is not threaded in any implementation.

### 9.1Internal Changes

Internal changes have been made to this routine as follows:
• At Mark 27.1: Previously, it was not possible to modify the objective function once it was set or to edit the model once a solver had been called. These limitations have been removed and the associated error codes were removed.
For details of all known issues which have been reported for the NAG Library please refer to the Known Issues.

## 10Example

In this example, we demonstrate how to declare a least squares problem through e04rmf and solve it with e04fff on a very simple example. Here $n=2$, ${m}_{r}=3$ and the residuals are computed by:
 $r1(x) = x(1)+ x(2)- 0.9 r2(x) = 2x(1)+ x(2)- 1.9 r3(x) = 3x(1)+ x(2)- 3.0$
The expected result is:
 $x=(0.95,0.10)$
with an objective value of $0.015$.