Here we give the subroutines funobj and funcon for the example of Section Identifying structure in the objective and constraints, repeated here for convenience:

This problem has 4 variables, 3 nonlinear objective variables, 2 nonlinear Jacobian variables, 2 nonlinear constraints and 1 linear constraint. The objective has some linear terms that we include as an extra "free row'' (with infinite bounds). The calling program must assign the values
|
m |
= |
4 |
|
n |
= |
4 |
|
nnCon |
= |
2 |
|
nnObj |
= |
3 |
|
nnJac |
= |
2 |
|
iObj |
= |
4 |
Subroutine funobj works with the nonlinear objective variables (x1, x2, x3). Since x3 occurs only linearly in the constraints, we have placed it after the nonlinear Jacobian variables (x1, x2).
For interest, we test mode to economize on gradient evaluations (even though they are cheap here). Note that No derivative linesearch would have to be specified, otherwise all entries would have mode = 2.
Click here to view the Toy problem subroutine funobj.
Subroutine funcon involves only (x1, x2). For convenience we treat the Jacobian as a dense matrix. In Fortran it is preferable to access (large) two-dimensional arrays column-wise, as shown. Since funcon is called before funobj, we test nState here to print a message on the first and last entries.
Click here to view the Toy problem subroutine funcon.