NAG FL Interface
e04rmf (handle_​set_​nlnls)

1 Purpose

e04rmf 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.

2 Specification

Fortran Interface
Subroutine e04rmf ( handle, nres, isparse, nnzrd, irowrd, icolrd, ifail)
Integer, Intent (In) :: nres, isparse, nnzrd, irowrd(nnzrd), icolrd(nnzrd)
Integer, Intent (Inout) :: ifail
Type (c_ptr), Intent (In) :: handle
C Header Interface
#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.

3 Description

After the initialization routine e04raf has been called and unless the objective function has already been defined, e04rmf 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 xn fx= j=1 mr rj x 2    subject to lxxux ,     
where x is an n-dimensional variable vector and rix 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
rjx 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.

4 References


5 Arguments

1: handle Type (c_ptr) Input
On entry: the handle to the problem. It needs to be initialized by e04raf and must not be changed before the call to e04rmf.
2: nres Integer Input
On entry: mr, the number of residuals in the objective function.
If nres=0, no objective function will be defined and irowrd and icolrd will not be referenced.
Constraint: nres0.
3: isparse Integer Input
On entry: is a flag indicating if the nonzero structure of the first derivative matrix is dense or sparse.
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 nnzrd=n×mr and the vectors irowrd and icolrd filled as:
  • irowrd=1,2,,n,1,2,,n,,1,2,,n;
  • icolrd=1,1,,1,2,2,,2,,mr,mr,,mr.
The sparsity structure of the first derivative matrix will be supplied by nnzrd, irowrd and icolrd.
Constraint: isparse=0 or 1.
4: nnzrd Integer Input
On entry: the number of nonzeros in the first derivative matrix.
Constraint: if isparse=1 and nres>0, nnzrd>0.
5: irowrdnnzrd Integer array Input
6: icolrdnnzrd 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×mr. 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.
  • 1irowrdln, for l=1,2,,nnzrd;
  • 1icolrdlnres, for l=1,2,,nnzrd.
7: 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 since useful values can be provided in some output arguments even when ifail0 on exit. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry 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:
The supplied handle does not define a valid handle to the data structure for the NAG optimization modelling suite. It has not been initialized by e04raf or it has been corrupted.
The Hessians of nonlinear functions have already been defined, a nonlinear objective cannot be added.
The problem cannot be modified in this phase any more, the solver has already been called.
The objective function has already been defined.
On entry, isparse=value.
Constraint: isparse=0 or 1.
On entry, nnzrd=value.
Constraint: nnzrd>0.
On entry, nres=value.
Constraint: nres0.
On entry, i=value, icolrdi=value and nres=value.
Constraint: 1icolrdinres.
On entry, i=value, irowrdi=value and n=value.
Constraint: 1irowrdin.
On entry, more than one element of first derivative matrix has row index value and column index value.
Constraint: each element of first derivative matrix must have a unique row and column index.
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.
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.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

Not applicable.

8 Parallelism and Performance

e04rmf is not threaded in any implementation.

9 Further Comments


10 Example

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, mr=3 and the residuals are computed by:
r1x = x1+ x2- 0.9 r2x = 2x1+ x2- 1.9 r3x = 3x1+ x2- 3.0  
The expected result is:
with an objective value of 0.015.

10.1 Program Text

Program Text (e04rmfe.f90)

10.2 Program Data


10.3 Program Results

Program Results (e04rmfe.r)