## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

e04rff is a part of the NAG optimization modelling suite and defines or redefines the objective function of the problem to be linear or quadratic.

## 2Specification

Fortran Interface
 Subroutine e04rff ( nnzc, idxc, c, nnzh, h,
 Integer, Intent (In) :: nnzc, idxc(nnzc), nnzh, irowh(nnzh), icolh(nnzh) Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: c(nnzc), h(nnzh) Type (c_ptr), Intent (In) :: handle
#include <nag.h>
 void e04rff_ (void **handle, const Integer *nnzc, const Integer idxc[], const double c[], const Integer *nnzh, const Integer irowh[], const Integer icolh[], const double h[], Integer *ifail)
The routine may be called by the names e04rff or nagf_opt_handle_set_quadobj.

## 3Description

After the handle has been initialized (e.g., e04raf has been called), e04rff may be used to define the objective function of the problem as a quadratic function ${c}^{\mathrm{T}}x+\frac{1}{2}{x}^{\mathrm{T}}Hx$ or a sparse linear function ${c}^{\mathrm{T}}x$. If the objective function has already been defined, it will be overwritten. If e04rff is called with no nonzeroes in either $c$ or $H$, any existing objective function is removed, no new one is added and the problem will be solved as a feasible point problem. e04tef may be used to set individual elements ${c}_{i}$ of the linear objective.
This objective function will typically be used for
Linear Programming (LP)
 $minimize x∈ℝn cTx (a) subject to lB≤Bx≤uB, (b) lx≤x≤ux , (c)$ (1)
 $minimize x∈ℝn 12 xTHx + cTx (a) subject to lB≤Bx≤uB, (b) lx≤x≤ux, (c)$ (2)
or for Semidefinite Programming problems with bilinear matrix inequalities (BMI-SDP)
 $minimize x∈ℝn 12 xTHx + cTx (a) subject to ∑ i,j=1 n xi xj Qijk + ∑ i=1 n xi Aik - A0k ⪰ 0 , k=1,…,mA , (b) lB≤Bx≤uB, (c) lx≤x≤ux. (d)$ (3)
The matrix $H$ is a sparse symmetric $n×n$ matrix. It does not need to be positive definite. 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{nnzc}$Integer Input
On entry: the number of nonzero elements in the sparse vector $c$.
If ${\mathbf{nnzc}}=0$, $c$ is considered to be zero and the arrays idxc and c will not be referenced.
Constraint: ${\mathbf{nnzc}}\ge 0$.
3: $\mathbf{idxc}\left({\mathbf{nnzc}}\right)$Integer array Input
4: $\mathbf{c}\left({\mathbf{nnzc}}\right)$Real (Kind=nag_wp) array Input
On entry: the nonzero elements of the sparse vector $c$. ${\mathbf{idxc}}\left(i\right)$ must contain the index of ${\mathbf{c}}\left(\mathit{i}\right)$ in the vector, for $\mathit{i}=1,2,\dots ,{\mathbf{nnzc}}$. The elements must be stored in ascending order. Note that $n$ is the current number of variables in the model.
Constraints:
• $1\le {\mathbf{idxc}}\left(\mathit{i}\right)\le n$, for $\mathit{i}=1,2,\dots ,{\mathbf{nnzc}}$;
• ${\mathbf{idxc}}\left(\mathit{i}\right)<{\mathbf{idxc}}\left(\mathit{i}+1\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{nnzc}}-1$.
5: $\mathbf{nnzh}$Integer Input
On entry: the number of nonzero elements in the upper triangle of the matrix $H$.
If ${\mathbf{nnzh}}=0$, the matrix $H$ is considered to be zero, the objective function is linear and irowh, icolh and h will not be referenced.
Constraint: ${\mathbf{nnzh}}\ge 0$.
6: $\mathbf{irowh}\left({\mathbf{nnzh}}\right)$Integer array Input
7: $\mathbf{icolh}\left({\mathbf{nnzh}}\right)$Integer array Input
8: $\mathbf{h}\left({\mathbf{nnzh}}\right)$Real (Kind=nag_wp) array Input
On entry: arrays irowh, icolh and h store the nonzeros of the upper triangle of the matrix $H$ in coordinate storage (CS) format (see Section 2.1.1 in the F11 Chapter Introduction). irowh specifies one-based row indices, icolh specifies one-based column indices and h specifies the values of the nonzero elements in such a way that ${h}_{ij}={\mathbf{h}}\left(l\right)$ where $i={\mathbf{irowh}}\left(l\right)$, $j={\mathbf{icolh}}\left(\mathit{l}\right)$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzh}}$. No particular order is expected, but elements should not repeat.
Constraint: $1\le {\mathbf{irowh}}\left(\mathit{l}\right)\le {\mathbf{icolh}}\left(\mathit{l}\right)\le n$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzh}}$.
9: $\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{nnzc}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nnzc}}\ge 0$.
On entry, ${\mathbf{nnzh}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nnzh}}\ge 0$.
${\mathbf{ifail}}=7$
On entry, $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{idxc}}\left(i\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{idxc}}\left(i+1\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{idxc}}\left(\mathit{i}\right)<{\mathbf{idxc}}\left(i+1\right)$ (ascending order).
On entry, $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{idxc}}\left(i\right)=⟨\mathit{\text{value}}⟩$ and $n=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{idxc}}\left(i\right)\le n$.
${\mathbf{ifail}}=8$
On entry, $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{icolh}}\left(\mathit{i}\right)=⟨\mathit{\text{value}}⟩$ and $n=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{icolh}}\left(\mathit{i}\right)\le n$.
On entry, $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{irowh}}\left(\mathit{i}\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{icolh}}\left(\mathit{i}\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{irowh}}\left(\mathit{i}\right)\le {\mathbf{icolh}}\left(\mathit{i}\right)$ (elements within the upper triangle).
On entry, $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{irowh}}\left(\mathit{i}\right)=⟨\mathit{\text{value}}⟩$ and $n=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{irowh}}\left(\mathit{i}\right)\le n$.
On entry, more than one element of h has row index $⟨\mathit{\text{value}}⟩$ and column index $⟨\mathit{\text{value}}⟩$.
Constraint: each element of h 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

e04rff 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

This example demonstrates how to use nonlinear semidefinite programming to find a nearest correlation matrix satisfying additional requirements. This is a viable alternative to routines g02aaf, g02abf, g02ajf or g02anf as it easily allows you to add further constraints on the correlation matrix. In this case a problem with a linear matrix inequality and a quadratic objective function is formulated to find the nearest correlation matrix in the Frobenius norm preserving the nonzero pattern of the original input matrix. However, additional box bounds (e04rhf) or linear constraints (e04rjf) can be readily added to further bind individual elements of the new correlation matrix or new matrix inequalities (e04rnf) to restrict its eigenvalues.
The problem is as follows (to simplify the notation only the upper triangular parts are shown). To a given $m×m$ symmetric input matrix $G$
 $G = ( g11 ⋯ g1m ⋱ ⋮ gmm )$
find correction terms ${x}_{1},\dots ,{x}_{n}$ which form symmetric matrix $\overline{G}$
 $G¯ = ( g¯11 g¯12 ⋯ g¯1m g¯22 ⋯ g¯2m ⋱ ⋮ g¯mm ) = ( 1 g12+x1 g13+x2 ⋯ g1m+xi 1 g23+x3 1 ⋮ ⋱ 1 gm-1m+xn 1 )$
so that the following requirements are met:
1. (a)It is a correlation matrix, i.e., symmetric positive semidefinite matrix with a unit diagonal. This is achieved by the way $\overline{G}$ is assembled and by a linear matrix inequality
 $G¯ = x1 ( 0 1 0 ⋯ 0 0 0 ⋯ 0 0 ⋯ 0 ⋱ ⋮ 0 ) + x2 ( 0 0 1 ⋯ 0 0 0 ⋯ 0 0 ⋯ 0 ⋱ ⋮ 0 ) + x3 ( 0 0 0 ⋯ 0 0 1 ⋯ 0 0 ⋯ 0 ⋱ ⋮ 0 ) + ⋯ + xn ( 0 ⋯ 0 0 0 ⋱ ⋮ ⋮ ⋮ 0 0 0 0 1 0 ) - ( −1 -g12 -g13 ⋯ -g1m −1 -g23 ⋯ -g2m −1 ⋯ -g3m ⋱ ⋮ −1 ) ⪰ 0 .$
2. (b)$\overline{G}$ is nearest to $G$ in the Frobenius norm, i.e., it minimizes the Frobenius norm of the difference which is equivalent to:
 $minimize ​12 ∑i≠j ( g¯ ij -gij) 2 = ∑ i=1 n xi2 .$
3. (c)$\overline{G}$ preserves the nonzero structure of $G$. This is met by defining ${x}_{i}$ only for nonzero elements ${g}_{ij}$.
For the input matrix
 $G = ( 2 −1 0 0 −1 2 −1 0 0 −1 2 −1 0 0 −1 2 )$
the result is
 $G¯ = ( 1.0000 -0.6823 0.0000 0.0000 -0.6823 1.0000 -0.5344 0.0000 0.0000 -0.5344 1.0000 -0.6823 0.0000 0.0000 -0.6823 1.0000 ) .$