Documentation Center

  • Trial Software
  • Product Updates

Nonlinear Equality and Inequality Constraints

For routines that permit equality constraints, nonlinear equality constraints must be computed with the nonlinear inequality constraints. For linear equalities, the coefficients of the equalities are passed in through the matrix Aeq and the right-hand-side vector beq.

For example, if you have the nonlinear equality constraint and the nonlinear inequality constraint x1x2 ≥ –10, rewrite them as

and then solve the problem using the following steps.

Step 1: Write a file objfun.m.

function f = objfun(x)
f = exp(x(1))*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1);

Step 2: Write a file confuneq.m for the nonlinear constraints.

function [c, ceq] = confuneq(x)
% Nonlinear inequality constraints
c = -x(1)*x(2) - 10;
% Nonlinear equality constraints
ceq = x(1)^2 + x(2) - 1;

Step 3: Invoke constrained optimization routine.

x0 = [-1,1];            % Make a starting guess at the solution
options = optimoptions(@fmincon,'Algorithm','sqp');
[x,fval] = fmincon(@objfun,x0,[],[],[],[],[],[],... 

After 21 function evaluations, the solution produced is

x =
   -0.7529    0.4332
fval =

[c,ceq] = confuneq(x) % Check the constraint values at x

c =
ceq =

Note that ceq is equal to 0 within the default tolerance on the constraints of 1.0e-006 and that c is less than or equal to 0, as desired.

Was this topic helpful?