Accelerating the pace of engineering and science

Documentation Center

• Trials

Minimization with Linear Equality Constraints

The trust-region reflective method for fmincon can handle linear equality constraints if no other constraints exist. Suppose you want to solve

The objective function is coded in the function brownfgh.m, where n = 1000, such that Aeq·x = beq for Aeq that has 100 equations (so Aeq is a 100-by-1000 matrix).

Step 1: Write a file brownfgh.m that computes the objective function, the gradient of the objective, and the sparse tridiagonal Hessian 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 GradObj 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```

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;
'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 TolFun. The final function value is given by fval.

```exitflag,fval,output

exitflag =
3

fval =
205.9313

output =
iterations: 22
funcCount: 23
cgiterations: 30
firstorderopt: 0.0027
algorithm: 'trust-region-reflective'
message: [1x471 char]
constrviolation: 2.2249e-13```

The linear equalities are satisfied at x.

```norm(Aeq*x-beq)

ans =
1.1938e-12```