E04 Chapter Contents
E04 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentE04VJF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

E04VJF may be used before E04VHF to determine the sparsity pattern for the Jacobian.

## 2  Specification

 SUBROUTINE E04VJF ( NF, N, USRFUN, IAFUN, JAVAR, A, LENA, NEA, IGFUN, JGVAR, LENG, NEG, X, XLOW, XUPP, CW, LENCW, IW, LENIW, RW, LENRW, CUSER, IUSER, RUSER, IFAIL)
 INTEGER NF, N, IAFUN(LENA), JAVAR(LENA), LENA, NEA, IGFUN(LENG), JGVAR(LENG), LENG, NEG, LENCW, IW(LENIW), LENIW, LENRW, IUSER(*), IFAIL REAL (KIND=nag_wp) A(LENA), X(N), XLOW(N), XUPP(N), RW(LENRW), RUSER(*) CHARACTER(8) CW(LENCW), CUSER(*) EXTERNAL USRFUN

## 3  Description

When using E04VHF, if you set the optional parameter ${\mathbf{Derivative Option}}=0$ and USRFUN provides none of the derivatives, you may need to call E04VJF to determine the input arrays IAFUN, JAVAR, A, IGFUN and JGVAR. These arrays define the pattern of nonzeros in the Jacobian matrix. A typical sequence of calls could be
```CALL E04VGF (CW, LENCW, ... )
CALL E04VJF (NF, N, ... )
CALL E04VLF ('Derivative Option = 0', CW, ... )
CALL E04VHF (START, NF, ... )```
E04VJF determines the sparsity pattern for the Jacobian and identifies the constant elements automatically. To do so, E04VJF approximates the problem functions, $F\left(x\right)$, at three random perturbations of the given initial point $x$. If an element of the approximate Jacobian is the same at all three points, then it is taken to be constant. If it is zero, it is taken to be identically zero. Since the random points are not chosen close together, the heuristic will correctly classify the Jacobian elements in the vast majority of cases. In general, E04VJF finds that the Jacobian can be permuted to the form:
 $Gx A3 A2 A4 ,$
where ${A}_{2}$, ${A}_{3}$ and ${A}_{4}$ are constant. Note that $G\left(x\right)$ might contain elements that are also constant, but E04VJF must classify them as nonlinear. This is because E04VHF ‘removes’ linear variables from the calculation of $F$ by setting them to zero before calling USRFUN. A knowledgeable user would be able to move such elements from $F\left(x\right)$ in USRFUN and enter them as part of IAFUN, JAVAR and A for E04VHF.

## 4  References

Hock W and Schittkowski K (1981) Test Examples for Nonlinear Programming Codes. Lecture Notes in Economics and Mathematical Systems 187 Springer–Verlag

## 5  Arguments

Note: all optional parameters are described in detail in Section 12.1 in E04VHF.
1:     $\mathrm{NF}$ – INTEGERInput
On entry: $\mathit{nf}$, the number of problem functions in $F\left(x\right)$, including the objective function (if any) and the linear and nonlinear constraints. Simple upper and lower bounds on $x$ can be defined using the arguments XLOW and XUPP and should not be included in $F$.
Constraint: ${\mathbf{NF}}>0$.
2:     $\mathrm{N}$ – INTEGERInput
On entry: $n$, the number of variables.
Constraint: ${\mathbf{N}}>0$.
3:     $\mathrm{USRFUN}$ – SUBROUTINE, supplied by the user.External Procedure
USRFUN must define the problem functions $F\left(x\right)$. This subroutine is passed to E04VJF as the external argument USRFUN.
The specification of USRFUN is:
 SUBROUTINE USRFUN ( STATUS, N, X, NEEDF, NF, F, NEEDG, LENG, G, CUSER, IUSER, RUSER)
 INTEGER STATUS, N, NEEDF, NF, NEEDG, LENG, IUSER(*) REAL (KIND=nag_wp) X(N), F(NF), G(LENG), RUSER(*) CHARACTER(8) CUSER(*)
1:     $\mathrm{STATUS}$ – INTEGERInput/Output
On entry: indicates the first call to USRFUN.
${\mathbf{STATUS}}=0$
There is nothing special about the current call to USRFUN.
${\mathbf{STATUS}}=1$
E04VJF is calling your subroutine for the first time. Some data may need to be input or computed and saved.
On exit: may be used to indicate that you are unable to evaluate $F$ at the current $x$. (For example, the problem functions may not be defined there).
E04VJF evaluates $F\left(x\right)$ at random perturbation of the initial point $x$, say ${x}_{p}$. If the functions cannot be evaluated at ${x}_{p}$, you can set ${\mathbf{STATUS}}=-1$, E04VJF will use another random perturbation.
If for some reason you wish to terminate the current problem, set ${\mathbf{STATUS}}\le -2$.
2:     $\mathrm{N}$ – INTEGERInput
On entry: $n$, the number of variables, as defined in the call to E04VJF.
3:     $\mathrm{X}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: the variables $x$ at which the problem functions are to be calculated. The array $x$ must not be altered.
4:     $\mathrm{NEEDF}$ – INTEGERInput
On entry: indicates if F must be assigned during the call to USRFUN (see F).
5:     $\mathrm{NF}$ – INTEGERInput
On entry: $\mathit{nf}$, the number of problem functions.
6:     $\mathrm{F}\left({\mathbf{NF}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output
On entry: this will be set by E04VJF.
On exit: the computed $F\left(x\right)$ according to the setting of NEEDF.
If ${\mathbf{NEEDF}}=0$, F is not required and is ignored.
If ${\mathbf{NEEDF}}>0$, the components of $F\left(x\right)$ must be calculated and assigned to F. E04VJF will always call USRFUN with ${\mathbf{NEEDF}}>0$.
To simplify the code, you may ignore the value of NEEDF and compute $F\left(x\right)$ on every entry to USRFUN.
7:     $\mathrm{NEEDG}$ – INTEGERInput
On entry: E04VJF will call USRFUN with ${\mathbf{NEEDG}}=0$ to indicate that G is not required.
8:     $\mathrm{LENG}$ – INTEGERInput
On entry: the dimension of the array G as declared in the (sub)program from which E04VJF is called.
9:     $\mathrm{G}\left({\mathbf{LENG}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output
On entry: concerns the calculations of the derivatives of the function $f\left(x\right)$.
On exit: E04VJF will always call USRFUN with ${\mathbf{NEEDG}}=0$: G is not required to be set on exit but must be declared correctly.
10:   $\mathrm{CUSER}\left(*\right)$ – CHARACTER(8) arrayUser Workspace
11:   $\mathrm{IUSER}\left(*\right)$ – INTEGER arrayUser Workspace
12:   $\mathrm{RUSER}\left(*\right)$ – REAL (KIND=nag_wp) arrayUser Workspace
USRFUN is called with the arguments CUSER, IUSER and RUSER as supplied to E04VJF. You should use the arrays CUSER, IUSER and RUSER to supply information to USRFUN.
USRFUN must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which E04VJF is called. Arguments denoted as Input must not be changed by this procedure.
4:     $\mathrm{IAFUN}\left({\mathbf{LENA}}\right)$ – INTEGER arrayOutput
5:     $\mathrm{JAVAR}\left({\mathbf{LENA}}\right)$ – INTEGER arrayOutput
6:     $\mathrm{A}\left({\mathbf{LENA}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: define the coordinates $\left(i,j\right)$ and values ${A}_{ij}$ of the nonzero elements of the linear part $A$ of the function $F\left(x\right)=f\left(x\right)+Ax$.
In particular, NEA triples $\left({\mathbf{IAFUN}}\left(k\right),{\mathbf{JAVAR}}\left(k\right),{\mathbf{A}}\left(k\right)\right)$ define the row and column indices $i={\mathbf{IAFUN}}\left(k\right)$ and $j={\mathbf{JAVAR}}\left(k\right)$ of the element ${A}_{ij}={\mathbf{A}}\left(k\right)$.
7:     $\mathrm{LENA}$ – INTEGERInput
On entry: the dimension of the arrays IAFUN, JAVAR and A that hold $\left(i,j,{A}_{ij}\right)$ as declared in the (sub)program from which E04VJF is called. LENA should be an overestimate of the number of elements in the linear part of the Jacobian.
Constraint: ${\mathbf{LENA}}\ge 1$.
8:     $\mathrm{NEA}$ – INTEGEROutput
On exit: is the number of nonzero entries in $A$ such that $F\left(x\right)=f\left(x\right)+Ax$.
9:     $\mathrm{IGFUN}\left({\mathbf{LENG}}\right)$ – INTEGER arrayOutput
10:   $\mathrm{JGVAR}\left({\mathbf{LENG}}\right)$ – INTEGER arrayOutput
On exit: define the coordinates $\left(i,j\right)$ of the nonzero elements of $G$, the nonlinear part of the derivatives $J\left(x\right)=G\left(x\right)+A$ of the function $F\left(x\right)=f\left(x\right)+Ax$.
11:   $\mathrm{LENG}$ – INTEGERInput
On entry: the dimension of the arrays IGFUN and JGVAR that define the varying Jacobian elements $\left(i,j,{G}_{ij}\right)$ as declared in the (sub)program from which E04VJF is called. LENG should be an overestimate of the number of elements in the nonlinear part of the Jacobian.
Constraint: ${\mathbf{LENG}}\ge 1$.
12:   $\mathrm{NEG}$ – INTEGEROutput
On exit: the number of nonzero entries in $G$.
13:   $\mathrm{X}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: an initial estimate of the variables $x$. The contents of $x$ will be used by E04VJF in the call of USRFUN, and so each element of X should be within the bounds given by XLOW and XUPP.
14:   $\mathrm{XLOW}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput
15:   $\mathrm{XUPP}\left({\mathbf{N}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: contain the lower and upper bounds ${l}_{x}$ and ${u}_{x}$ on the variables $x$.
To specify a nonexistent lower bound ${\left[{l}_{x}\right]}_{j}=-\infty$, set ${\mathbf{XLOW}}\left(j\right)\le -\mathit{bigbnd}$, where $\mathit{bigbnd}$ is the optional parameter Infinite Bound Size. To specify a nonexistent upper bound ${\mathbf{XUPP}}\left(j\right)\ge \mathit{bigbnd}$.
To fix the $j$th variable (say, ${x}_{j}=\beta$, where $\left|\beta \right|<\mathit{bigbnd}$), set ${\mathbf{XLOW}}\left(j\right)={\mathbf{XUPP}}\left(j\right)=\beta$.
16:   $\mathrm{CW}\left({\mathbf{LENCW}}\right)$ – CHARACTER(8) arrayCommunication Array
17:   $\mathrm{LENCW}$ – INTEGERInput
On entry: the dimension of the array CW as declared in the (sub)program from which E04VJF is called.
Constraint: ${\mathbf{LENCW}}\ge 600$.
18:   $\mathrm{IW}\left({\mathbf{LENIW}}\right)$ – INTEGER arrayCommunication Array
19:   $\mathrm{LENIW}$ – INTEGERInput
On entry: the dimension of the array IW as declared in the (sub)program from which E04VJF is called.
Constraint: ${\mathbf{LENIW}}\ge 600$.
20:   $\mathrm{RW}\left({\mathbf{LENRW}}\right)$ – REAL (KIND=nag_wp) arrayCommunication Array
21:   $\mathrm{LENRW}$ – INTEGERInput
On entry: the dimension of the array RW as declared in the (sub)program from which E04VJF is called.
Constraint: ${\mathbf{LENRW}}\ge 600$.
22:   $\mathrm{CUSER}\left(*\right)$ – CHARACTER(8) arrayUser Workspace
23:   $\mathrm{IUSER}\left(*\right)$ – INTEGER arrayUser Workspace
24:   $\mathrm{RUSER}\left(*\right)$ – REAL (KIND=nag_wp) arrayUser Workspace
CUSER, IUSER and RUSER are not used by E04VJF, but are passed directly to USRFUN and should be used to pass information to this routine.
25:   $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ 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).

## 6  Error 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{LENCW}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LENCW}}\ge 600$.
On entry, ${\mathbf{LENIW}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LENIW}}\ge 600$.
On entry, ${\mathbf{LENRW}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LENRW}}\ge 600$.
The initialization routine E04VGF has not been called.
${\mathbf{IFAIL}}=2$
On entry, ${\mathbf{LENA}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LENA}}\ge 1$.
On entry, ${\mathbf{LENG}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LENG}}\ge 1$.
${\mathbf{IFAIL}}=3$
User-supplied routine USRFUN indicates that functions are undefined near given point X.
You have indicated that the problem functions are undefined by setting ${\mathbf{STATUS}}=-1$ on exit from USRFUN. This exit occurs if E04VJF is unable to find a point at which the functions are defined.
${\mathbf{IFAIL}}=4$
User-supplied routine USRFUN requested termination.
You have indicated the wish to terminate the call to E04VJF by setting STATUS to a value $\text{}<-1$ on exit from USRFUN.
${\mathbf{IFAIL}}=5$
Either LENA or LENG is too small. Increase both of them and corresponding array sizes. ${\mathbf{LENA}}=〈\mathit{\text{value}}〉$ and ${\mathbf{LENG}}=〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=6$
Cannot estimate Jacobian structure at given point X.
${\mathbf{IFAIL}}=7$
Internal error: memory allocation failed when attempting to allocate workspace sizes $〈\mathit{\text{value}}〉$, $〈\mathit{\text{value}}〉$ and $〈\mathit{\text{value}}〉$. Please contact NAG.
${\mathbf{IFAIL}}=8$
${\mathbf{IFAIL}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

Not applicable.

## 8  Parallelism and Performance

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

None.

## 10  Example

This example shows how to call E04VJF to determine the sparsity pattern of the Jacobian before calling E04VHF to solve a sparse nonlinear programming problem without providing the Jacobian information in USRFUN.
It is a reformulation of Problem 74 from Hock and Schittkowski (1981) and involves the minimization of the nonlinear function
 $fx = 10-6 x33 + 23 × 10-6 x43+3 x3+2 x4$
subject to the bounds
 $-0.55≤x1≤ 0.55, -0.55≤x2≤ 0.55, 0≤x3≤ 1200, 0≤x4≤ 1200,$
to the nonlinear constraints
 $1000sin-x1-0.25+1000sin-x2-0.25-x3 = -894.8, 1000sinx1-0.25+1000sinx1-x2-0.25-x4 = -894.8, 1000sinx2-0.25+1000sinx2-x1-0.25 = -1294.8,$
and to the linear constraints
 $-x1+x2≥-0.55, -x1-x2≥-0.55.$
The initial point, which is infeasible, is
 $x0 = 0, 0, 0, 0 T ,$
and $f\left({x}_{0}\right)=0$.
The optimal solution (to five figures) is
 $x*=0.11887,-0.39623,679.94,1026.0T,$
and $f\left({x}^{*}\right)=5126.4$. All the nonlinear constraints are active at the solution.
The formulation of the problem combines the constraints and the objective into a single vector ($F$).
 $F = 1000 sin -x1 - 0.25 + 1000 sin -x2 - 0.25 - x3 1000 sin x1 - 0.25 + 1000 sin x1 - x2 - 0.25 - x4 1000 sin x2 - 0.25 + 1000 sin x2 - x1 - 0.25 -x1 + x2 x1 - x2 10-6 x33 + 23 × 10-6 x43 + 3x3 + 2x4$

### 10.1  Program Text

Program Text (e04vjfe.f90)

### 10.2  Program Data

Program Data (e04vjfe.d)

### 10.3  Program Results

Program Results (e04vjfe.r)