Optimization Toolbox | ![]() ![]() |
Nonlinear Minimization with Equality Constraints
The large-scale method for fmincon
can handle equality constraints if no other constraints exist. Suppose you want to minimize the same objective as in Eq. 2-7, which is coded in the function brownfgh.m
, where n = 1000
, such that for Aeq that has 100 equations (so Aeq is a 100-by-1000 matrix).
Step 1: Write an M-file brownfgh.m that computes the objective function, the gradient of the objective, and the sparse tridiagonal Hessian matrix.
As before, this file is rather long and is not included here. You can view the code with the command
Because brownfgh
computes the gradient and Hessian values as well as the objective function, you need to use optimset
to indicate that this information is available in brownfgh
, using the GradObj
and Hessian
parameters.
The sparse matrix Aeq
and vector beq
are available in the file browneq.mat
:
The linear constraint system is 100-by-1000, has unstructured sparsity (use spy
(Aeq)
to view the sparsity structure), and is not too badly ill-conditioned:
Step 2: Call a nonlinear minimization routine with a starting point xstart.
fun = @brownfgh; load browneq % Get Aeq and beq, the linear equalities n = 1000; xstart = -ones(n,1); xstart(2:2:n) = 1; options = optimset('GradObj','on','Hessian','on', ... 'PrecondBandWidth', inf); [x,fval,exitflag,output] = ... fmincon(fun,xstart,[],[],Aeq,beq,[],[],[],options);
Setting the parameter PrecondBandWidth
to inf
causes a sparse direct solver to be used instead of preconditioned conjugate gradients.
The exitflag
indicates convergence with the final function value fval
after 16 iterations:
exitflag = 1 fval = 205.9313 output = iterations: 16 funcCount: 16 cgiterations: 14 firstorderopt: 2.1434e-004 algorithm: 'large-scale: projected trust-region Newton'
The linear equalities are satisfied at x
.
![]() | Nonlinear Minimization with Bound Constraints and Banded Preconditioner | Nonlinear Minimization with a Dense but Structured Hessian and Equality Constraints | ![]() |