PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_opt_nlp2_sparse_jacobian (e04vj)
Purpose
nag_opt_nlp2_sparse_jacobian (e04vj) may be used before
nag_opt_nlp2_sparse_solve (e04vh) to determine the sparsity pattern for the Jacobian.
Syntax
[
iafun,
javar,
nea,
a,
igfun,
jgvar,
neg,
cw,
iw,
rw,
user,
ifail] = e04vj(
nf,
usrfun,
lena,
leng,
x,
xlow,
xupp,
cw,
iw,
rw, 'n',
n, 'user',
user)
[
iafun,
javar,
nea,
a,
igfun,
jgvar,
neg,
cw,
iw,
rw,
user,
ifail] = nag_opt_nlp2_sparse_jacobian(
nf,
usrfun,
lena,
leng,
x,
xlow,
xupp,
cw,
iw,
rw, 'n',
n, 'user',
user)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 22: |
lencw, leniw and lenrw were removed from the interface |
Description
When using
nag_opt_nlp2_sparse_solve (e04vh), if you set the optional parameter
and
usrfun provides none of the derivatives, you may need to call
nag_opt_nlp2_sparse_jacobian (e04vj) 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
[cw, iw, rw, ifail] = e04vg();
[..., cw, iw, rw, ...] = e04vj(...);
[cw, iw, rw, ifail] = e04vl('Derivative Option = 0', cw, iw, rw);
[..., cw, iw, rw, ...] = e04vh(...);
nag_opt_nlp2_sparse_jacobian (e04vj) determines the sparsity pattern for the Jacobian and identifies the constant elements automatically. To do so,
nag_opt_nlp2_sparse_jacobian (e04vj) approximates the problem functions,
, at three random perturbations of the given initial point
. 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,
nag_opt_nlp2_sparse_jacobian (e04vj) finds that the Jacobian can be permuted to the form:
where
,
and
are constant. Note that
might contain elements that are also constant, but
nag_opt_nlp2_sparse_jacobian (e04vj) must classify them as nonlinear. This is because
nag_opt_nlp2_sparse_solve (e04vh) ‘removes’ linear variables from the calculation of
by setting them to zero before calling
usrfun. A knowledgeable user would be able to move such elements from
in
usrfun and enter them as part of
iafun,
javar and
a for
nag_opt_nlp2_sparse_solve (e04vh).
References
Hock W and Schittkowski K (1981) Test Examples for Nonlinear Programming Codes. Lecture Notes in Economics and Mathematical Systems 187 Springer–Verlag
Parameters
Note: all optional parameters are described in detail in
Description of the s in
nag_opt_nlp2_sparse_solve (e04vh).
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
, the number of problem functions in
, including the objective function (if any) and the linear and nonlinear constraints. Simple upper and lower bounds on
can be defined using the arguments
xlow and
xupp and should not be included in
.
Constraint:
.
- 2:
– function handle or string containing name of m-file
-
usrfun must define the problem functions
. This function is passed to
nag_opt_nlp2_sparse_jacobian (e04vj) as the external argument
usrfun.
[status, f, g, user] = usrfun(status, n, x, needf, nf, f, needg, leng, g, user)
Input Parameters
- 1:
– int64int32nag_int scalar
-
Indicates the first call to
usrfun.
- There is nothing special about the current call to usrfun.
- nag_opt_nlp2_sparse_jacobian (e04vj) is calling your function for the first time. Some data may need to be input or computed and saved.
- 2:
– int64int32nag_int scalar
-
, the number of variables, as defined in the call to nag_opt_nlp2_sparse_jacobian (e04vj).
- 3:
– double array
-
The variables at which the problem functions are to be calculated. The array must not be altered.
- 4:
– int64int32nag_int scalar
-
Indicates if
f must be assigned during the call to
usrfun (see
f).
- 5:
– int64int32nag_int scalar
-
, the number of problem functions.
- 6:
– double array
-
This will be set by nag_opt_nlp2_sparse_jacobian (e04vj).
- 7:
– int64int32nag_int scalar
-
nag_opt_nlp2_sparse_jacobian (e04vj) will call
usrfun with
to indicate that
g is not required.
- 8:
– int64int32nag_int scalar
-
The dimension of the array
g.
- 9:
– double array
-
Concerns the calculations of the derivatives of the function .
- 10:
– Any MATLAB object
usrfun is called from
nag_opt_nlp2_sparse_jacobian (e04vj) with the object supplied to
nag_opt_nlp2_sparse_jacobian (e04vj).
Output Parameters
- 1:
– int64int32nag_int scalar
-
May be used to indicate that you are unable to evaluate
at the current
. (For example, the problem functions may not be defined there).
nag_opt_nlp2_sparse_jacobian (e04vj) evaluates at random perturbation of the initial point , say . If the functions cannot be evaluated at , you can set , nag_opt_nlp2_sparse_jacobian (e04vj) will use another random perturbation.
If for some reason you wish to terminate the current problem, set .
- 2:
– double array
-
The computed
according to the setting of
needf.
If
,
f is not required and is ignored.
If
, the components of
must be calculated and assigned to
f.
nag_opt_nlp2_sparse_jacobian (e04vj) will always call
usrfun with
.
To simplify the code, you may ignore the value of
needf and compute
on every entry to
usrfun.
- 3:
– double array
-
nag_opt_nlp2_sparse_jacobian (e04vj) will always call
usrfun with
:
g is not required to be set on exit but must be declared correctly.
- 4:
– Any MATLAB object
- 3:
– int64int32nag_int scalar
-
The dimension of the arrays
iafun,
javar and
a that hold
.
lena should be an
overestimate of the number of elements in the linear part of the Jacobian.
Constraint:
.
- 4:
– int64int32nag_int scalar
-
The dimension of the arrays
igfun and
jgvar that define the varying Jacobian elements
.
leng should be an
overestimate of the number of elements in the nonlinear part of the Jacobian.
Constraint:
.
- 5:
– double array
-
An initial estimate of the variables
. The contents of
will be used by
nag_opt_nlp2_sparse_jacobian (e04vj) in the call of
usrfun, and so each element of
x should be within the bounds given by
xlow and
xupp.
- 6:
– double array
- 7:
– double array
-
Contain the lower and upper bounds
and
on the variables
.
To specify a nonexistent lower bound
, set
, where
is the optional parameter
Infinite Bound Size. To specify a nonexistent upper bound
.
To fix the th variable (say, , where ), set .
- 8:
– cell array of strings
lencw, the dimension of the array, must satisfy the constraint
.
Constraint:
.
- 9:
– int64int32nag_int array
leniw, the dimension of the array, must satisfy the constraint
.
Constraint:
.
- 10:
– double array
lenrw, the dimension of the array, must satisfy the constraint
.
Constraint:
.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the arrays
x,
xlow,
xupp. (An error is raised if these dimensions are not equal.)
, the number of variables.
Constraint:
.
- 2:
– Any MATLAB object
user is not used by
nag_opt_nlp2_sparse_jacobian (e04vj), but is passed to
usrfun. Note that for large objects it may be more efficient to use a global variable which is accessible from the m-files than to use
user.
Output Parameters
- 1:
– int64int32nag_int array
- 2:
– int64int32nag_int array
-
Define the coordinates
and values
of the nonzero elements of the linear part
of the function
.
In particular,
nea triples
define the row and column indices
and
of the element
.
- 3:
– int64int32nag_int scalar
-
Is the number of nonzero entries in such that .
- 4:
– double array
-
Define the coordinates
and values
of the nonzero elements of the linear part
of the function
.
In particular,
nea triples
define the row and column indices
and
of the element
.
- 5:
– int64int32nag_int array
- 6:
– int64int32nag_int array
-
Define the coordinates of the nonzero elements of , the nonlinear part of the derivatives of the function .
- 7:
– int64int32nag_int scalar
-
The number of nonzero entries in .
- 8:
– cell array of strings
.
Communication array, used to store information between calls to nag_opt_nlp2_sparse_jacobian (e04vj).
- 9:
– int64int32nag_int array
.
Communication array, used to store information between calls to nag_opt_nlp2_sparse_jacobian (e04vj).
- 10:
– double array
.
Communication array, used to store information between calls to nag_opt_nlp2_sparse_jacobian (e04vj).
- 11:
– Any MATLAB object
- 12:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
Constraint: .
Constraint: .
Constraint: .
The initialization function
nag_opt_nlp2_sparse_init (e04vg) has not been called.
-
-
Constraint: .
Constraint: .
-
-
User-supplied function
usrfun indicates that functions are undefined near given point
x.
You have indicated that the problem functions are undefined by setting on exit from usrfun. This exit occurs if nag_opt_nlp2_sparse_jacobian (e04vj) is unable to find a point at which the functions are defined.
-
-
User-supplied function
usrfun requested termination.
You have indicated the wish to terminate the call to nag_opt_nlp2_sparse_jacobian (e04vj) by setting status to a value on exit from usrfun.
-
-
Either
lena or
leng is too small.
-
-
Cannot estimate Jacobian structure at given point
x.
-
-
Internal error.
-
-
Internal memory allocation was insufficient. Please contact
NAG.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
Not applicable.
Further Comments
None.
Example
This example shows how to call
nag_opt_nlp2_sparse_jacobian (e04vj) to determine the sparsity pattern of the Jacobian before calling
nag_opt_nlp2_sparse_solve (e04vh) 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
subject to the bounds
to the nonlinear constraints
and to the linear constraints
The initial point, which is infeasible, is
and
.
The optimal solution (to five figures) is
and
. All the nonlinear constraints are active at the solution.
The formulation of the problem combines the constraints and the objective into a single vector (
).
Open in the MATLAB editor:
e04vj_example
function e04vj_example
fprintf('e04vj example results\n\n');
nf = int64(6);
lena = int64(300);
leng = int64(300);
x = [ 0; 0; 0; 0];
xlow = [-0.55; -0.55; 0; 0];
xupp = [ 0.55; 0.55; 1200; 1200];
[cw, iw, rw, ifail] = e04vg;
[iarow, iacol, nea, a, igrow, igcol, neg, cw, iw, rw, cuser, ifail] = ...
e04vj(...
nf, @usrfun, lena, leng, x, xlow, xupp, cw, iw, rw);
fprintf(' Matrix A:\n');
fprintf(' Non-zero entries = %3d\n',nea);
fprintf(' values : ');
fprintf('%3.0f',a(1:nea));
fprintf('\n row indices : ');
fprintf('%3d',iarow(1:nea));
fprintf('\n column indices : ');
fprintf('%3d',iacol(1:nea));
fprintf('\n\n Matrix G:\n');
fprintf(' Non-zero entries = %3d\n',neg);
fprintf(' row indices : ');
fprintf('%3d',igrow(1:neg));
fprintf('\n column indices : ');
fprintf('%3d',igcol(1:neg));
fprintf('\n');
function [status, f, g, user] = ...
usrfun(status, n, x, needf, nf, f, needg, leng, g, user)
f(1) = 1000*sin(-x(1)-0.25) + 1000*sin(-x(2) -0.25) - x(3);
f(2) = 1000*sin(x(1)-0.25) + 1000*sin(x(1)-x(2) -0.25) - x(4);
f(3) = 1000*sin(x(2)-x(1)-0.25) + 1000*sin(x(2) -0.25);
f(4) = -x(1) + x(2);
f(5) = x(1) - x(2);
f(6) = 1.0d-6*x(3)^3 + 2.0d-6*x(4)^3/3 + 3*x(3) + 2*x(4);
e04vj example results
Matrix A:
Non-zero entries = 4
values : -1 1 1 -1
row indices : 4 5 4 5
column indices : 1 1 2 2
Matrix G:
Non-zero entries = 10
row indices : 1 2 3 1 2 3 6 6 1 2
column indices : 1 1 1 2 2 2 3 4 3 4
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015