This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Nonlinear Inequality Constraints

This example shows how to solve a scalar minimization problem with nonlinear inequality constraints. The problem is to find x that solves


subject to the constraints

x1x2x1x2 ≤ –1.5,
x1x2 ≥ –10.

Because neither of the constraints is linear, you cannot pass the constraints to fmincon at the command line. Instead you can create a second file, confun.m, that returns the value at both constraints at the current x in a vector c. The constrained optimizer, fmincon, is then invoked. Because fmincon expects the constraints to be written in the form c(x) ≤ 0, you must rewrite your constraints in the form

x1x2x1x2 + 1.5 ≤ 0,
x1x2 –10 ≤ 0.

Step 1: Write a file objfun.m for the objective function.

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 confun.m for the constraints.

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

Step 3: Invoke constrained optimization routine.

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

fmincon produces the solution x with function value fval:

x = 
   -9.5474  1.0474 
fval =

You can evaluate the constraints at the solution by entering

[c,ceq] = confun(x)

This returns numbers close to zero, such as

c =

   1.0e-14 *


ceq =


Note that both constraint values are, to within a small tolerance, less than or equal to 0; that is, x satisfies c(x) ≤ 0.

Related Topics