# NAG CL Interfacee04rtc (handle_​set_​qconstr_​fac)

Settings help

CL Name Style:

## 1Purpose

e04rtc is a part of the NAG optimization modelling suite and defines a new, or edits an existing, quadratic objective function or constraint of the problem using a factor of the quadratic coefficient matrix.

## 2Specification

 #include
 void e04rtc (void *handle, double s, Integer nnzr, const Integer idxr[], const double r[], Integer mf, Integer nnzf, const Integer irowf[], const Integer icolf[], const double f[], Integer *idqc, NagError *fail)
The function may be called by the names: e04rtc or nag_opt_handle_set_qconstr_fac.

## 3Description

After the handle has been initialized (e.g., e04rac has been called), e04rtc may be used to edit a model by adding or replacing a quadratic objective function or constraint of the form
 $12 xTFTFx + rTx$ (1)
and
 $12 xTFTFx + rTx + s≤0 ,$ (2)
respectively.
The matrix $F$ is a sparse $m×n$ matrix. It can be viewed as the factor of the symmetric matrix $Q={F}^{\mathrm{T}}F$ in a general quadratic function
 $12 xTQx + rTx + s .$ (3)
It is also acceptable if $F$ is a zero matrix, in which case the corresponding objective function or constraint becomes linear. If you have the full matrix $Q$ as input data, please call function e04rsc instead. Note that it is possible to temporarily disable and enable individual constraints in the model by e04tcc and e04tbc, respectively. See Section 4.1 in the E04 Chapter Introduction for more details about the NAG optimization modelling suite.

None.

## 5Arguments

1: $\mathbf{handle}$void * Input
On entry: the handle to the problem. It needs to be initialized (e.g., by e04rac) and must not be changed between calls to the NAG optimization modelling suite.
2: $\mathbf{s}$double Input
On entry: the constant term in quadratic constraint.
If ${\mathbf{idqc}}=-1$, s will not be referenced.
3: $\mathbf{nnzr}$Integer Input
On entry: the number of nonzero elements in the sparse vector $r$.
If ${\mathbf{nnzr}}=0$, $r$ is considered to be zero and the arrays idxr and r will not be referenced and may be NULL.
Constraint: ${\mathbf{nnzr}}\ge 0$.
4: $\mathbf{idxr}\left[{\mathbf{nnzr}}\right]$const Integer Input
5: $\mathbf{r}\left[{\mathbf{nnzr}}\right]$const double Input
On entry: the nonzero elements of the sparse vector $r$. ${\mathbf{idxr}}\left[i-1\right]$ must contain the index of ${\mathbf{r}}\left[\mathit{i}-1\right]$ in the vector, for $\mathit{i}=1,2,\dots ,{\mathbf{nnzr}}$. No particular order is expected, but elements should not repeat. Note that $n$ is the current number of variables in the problem.
Constraint: $1\le {\mathbf{idxr}}\left[\mathit{i}-1\right]\le n$, for $\mathit{i}=1,2,\dots ,{\mathbf{nnzr}}$.
6: $\mathbf{mf}$Integer Input
On entry: $m$, row dimension of matrix $F$.
Constraint: ${\mathbf{mf}}>0$.
7: $\mathbf{nnzf}$Integer Input
On entry: the number of nonzero elements in the matrix $F$.
If ${\mathbf{nnzf}}=0$, the matrix $F$ is considered to be zero, the objective function or constraint is linear and mf, irowf, icolf and f will not be referenced and may be NULL.
Constraint: ${\mathbf{nnzf}}\ge 0$.
8: $\mathbf{irowf}\left[{\mathbf{nnzf}}\right]$const Integer Input
9: $\mathbf{icolf}\left[{\mathbf{nnzf}}\right]$const Integer Input
10: $\mathbf{f}\left[{\mathbf{nnzf}}\right]$const double Input
On entry: arrays irowf, icolf and f store the nonzeros of the matrix $F$ in coordinate storage (CS) format (see Section 2.1.1 in the F11 Chapter Introduction). irowf specifies one-based row indices, icolf specifies one-based column indices and f specifies the values of the nonzero elements in such a way that ${F}_{ij}={\mathbf{f}}\left[l-1\right]$ where $i={\mathbf{irowf}}\left[l-1\right]$, $j={\mathbf{icolf}}\left[\mathit{l}-1\right]$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzf}}$. No particular order is expected, but elements should not repeat.
Constraint: $1\le {\mathbf{irowf}}\left[\mathit{l}-1\right]\le {\mathbf{mf}}\text{, ​}1\le {\mathbf{icolf}}\left[\mathit{l}-1\right]\le n$, for $\mathit{l}=1,2,\dots ,{\mathbf{nnzf}}$.
11: $\mathbf{idqc}$Integer * Input/Output
On entry:
${\mathbf{idqc}}=0$
A new quadratic constraint is created.
${\mathbf{idqc}}>0$
Specifies the index of an existing constraint to be replaced. i.e., replaces the idqcth constraint.
${\mathbf{idqc}}=-1$
A new quadratic objective is created and will replace any previously defined objective function.
Constraint: ${\mathbf{idqc}}\ge -1$.
On exit: if ${\mathbf{idqc}}=0$ on entry, then idqc is overwritten with the index of the new quadratic constraint. By definition, this is the number of quadratic constraints already defined plus one. Otherwise, idqc stays unchanged.
12: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_HANDLE
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.
NE_INT
nnzr and nnzf cannot be zero at the same time.
On entry, ${\mathbf{idqc}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{idqc}}\ge -1$.
On entry, ${\mathbf{mf}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{mf}}>0$.
On entry, ${\mathbf{nnzf}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nnzf}}\ge 0$.
On entry, ${\mathbf{nnzr}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nnzr}}\ge 0$.
NE_INTARR
On entry, $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{idxr}}\left[i-1\right]=⟨\mathit{\text{value}}⟩$ and $n=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{idxr}}\left[i-1\right]\le n$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_INVALID_CS
On entry, $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{icolf}}\left[\mathit{i}-1\right]=⟨\mathit{\text{value}}⟩$ and $n=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{icolf}}\left[\mathit{i}-1\right]\le n$.
On entry, $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{irowf}}\left[\mathit{i}-1\right]=⟨\mathit{\text{value}}⟩$ and ${\mathbf{mf}}=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{irowf}}\left[\mathit{i}-1\right]\le {\mathbf{mf}}$.
On entry, more than one element of f has row index $⟨\mathit{\text{value}}⟩$ and column index $⟨\mathit{\text{value}}⟩$.
Constraint: each element of f must have a unique row and column index.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_NOT_INCREASING
On entry, more than one element of idxr has index $⟨\mathit{\text{value}}⟩$.
Constraint: each element of idxr must have a unique index.
NE_PHASE
The problem cannot be modified right now, the solver is running.
NE_REF_MATCH
On entry, ${\mathbf{idqc}}=⟨\mathit{\text{value}}⟩$.
The given idqc does not match with any quadratic constraint already defined.

Not applicable.

## 8Parallelism and Performance

e04rtc is not threaded in any implementation.

None.

## 10Example

This example demonstrates how to define and solve a convex quadratic programming problem where the quadratic term is defined by its factors.
We solve the following norm minimization problem:
 $minimize x∈R3 ‖Ax-b‖22 subject to eTx=1, lx ≤ x ≤ ux,$
where
 $A= ( 0.493 0.382 0.0 0.0 0.270 0.475 ) , b= ( 0.2 0.4 ),$
 $lx= ( -1.0 -1.0 -1.0 ) , ux= ( 1.0 1.0 1.0 ),$
and $e\in {R}^{3}$ is vector of all ones. Note that
 $‖Ax-b‖22 = xTATAx - 2bTAx + bTb$
which is a convex quadratic function.
The optimal solution (to five significant figures) is
 $x*=(1.0000,-0.97221,0.97221)T,$
and the objective function value without the constant term ${b}^{\mathrm{T}}b$ is $0.13130$.

### 10.1Program Text

Program Text (e04rtce.c)

### 10.2Program Data

Program Data (e04rtce.d)

### 10.3Program Results

Program Results (e04rtce.r)