Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

The trust-region reflective method for `fmincon`

can
handle linear equality constraints if no other constraints exist.
Suppose you want to minimize

$$f(x)={\displaystyle \sum _{i=1}^{n-1}\left({\left({x}_{i}^{2}\right)}^{\left({x}_{i+1}^{2}+1\right)}+{\left({x}_{i+1}^{2}\right)}^{\left({x}_{i}^{2}+1\right)}\right)},$$

subject to some linear equality constraints. The objective function
is coded in the function `brownfgh.m`

. This example
takes `n = 1000`

. Furthermore, the `browneq.mat`

file
contains matrices `Aeq`

and `beq`

that
represent the linear constraints *Aeq*·*x* = *beq*. *Aeq* has
100 rows representing 100 linear constraints (so *Aeq* is
a 100-by-1000 matrix).

The file is lengthy so is not included here. View the code with the command

type brownfgh

Because `brownfgh`

computes the gradient and
Hessian values as well as the objective function, you need to use `optimoptions`

to indicate that this information
is available in `brownfgh`

, using the `SpecifyObjectiveGradient`

and `Hessian`

options.

The sparse matrix `Aeq`

and vector `beq`

are
available in the file `browneq.mat`

:

load browneq

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:

condest(Aeq*Aeq') ans = 2.9310e+006

fun = @brownfgh; load browneq % Get Aeq and beq, the linear equalities n = 1000; xstart = -ones(n,1); xstart(2:2:n) = 1; options = optimoptions('fmincon','SpecifyObjectiveGradient',true,'HessianFcn','objective',... 'Algorithm','trust-region-reflective'); [x,fval,exitflag,output] = ... fmincon(fun,xstart,[],[],Aeq,beq,[],[],[],options);

`fmincon`

prints the following exit message:

Local minimum possible. fmincon stopped because the final change in function value relative to its initial value is less than the default value of the function tolerance.

The `exitflag`

value of `3`

also
indicates that the algorithm terminated because the change in the
objective function value was less than the tolerance `OptimalityTolerance`

.
The final function value is given by `fval`

.

exitflag,fval,output exitflag = 3 fval = 205.9313 output = struct with fields: iterations: 22 funcCount: 23 stepsize: 0.0054 cgiterations: 30 firstorderopt: 0.0027 algorithm: 'trust-region-reflective' message: 'Local minimum possible.…' constrviolation: 2.2427e-13

The linear equalities are satisfied at `x`

.

norm(Aeq*x-beq) ans = 1.1926e-12

Was this topic helpful?