fseminf
Find minimum of semi-infinitely constrained multivariable nonlinear function
Syntax
Description
fseminf
is a nonlinear programming solver that finds the
minimum of a problem specified by
b and beq are vectors.
A and Aeq are matrices.
c(x), ceq(x), and Ki(x,wi) are functions that return vectors.
f(x) is a function that returns a scalar.
f(x), c(x), and ceq(x) can be nonlinear functions. The vectors (or matrices) Ki(x,wi) ≤ 0 are continuous functions of both x and an additional set of variables w1,w2,...,wn. The variables w1,w2,...,wn are vectors of length two, at most.
x, lb, and ub can be passed as vectors or matrices; see Matrix Arguments.
Examples
Minimize Function with Semi-Infinite Constraints
Minimize the function
,
subject to the constraints
for all .
The unconstrained objective function is minimized at . However, the constraint
for all
implies . Notice that , so
.
Therefore,
when .
To solve this problem using fseminf
, write the objective function as an anonymous function.
objfun = @(x)(x-1)^2;
Write the semi-infinite constraint function seminfcon
, which includes the nonlinear constraints [ ], initial sampling interval for (0 to 1 in steps of 0.01), and the semi-infinite constraint function . The code for the seminfcon
function appears at the end of this example.
Set the initial point x0 = 0.2
.
x0 = 0.2;
Specify the one semi-infinite constraint.
ntheta = 1;
Solve the problem by calling fseminf
and view the result.
x = fseminf(objfun,x0,ntheta,@seminfcon)
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 0.5000
The following code creates the seminfcon
function.
function [c, ceq, K1, s] = seminfcon(x,s) % No finite nonlinear inequality and equality constraints c = []; ceq = []; % Sample set if isnan(s) % Initial sampling interval s = [0.01 0]; end t = 0:s(1):1; % Evaluate the semi-infinite constraint K1 = (x - 0.5) - (t - 0.5).^2; end
Examine fseminf
Outputs
Minimize the function
,
subject to the constraints
for all .
This problem is formulated and solved in the example Minimize Function with Semi-Infinite Constraints which collects more information about the solution and solution process.
To solve this problem using fseminf
, write the objective function as an anonymous function.
objfun = @(x)(x-1)^2;
The code for the nonlinear and semi-infinite constraint function seminfcon
appears at the end of this example.
Set the initial point x0 = 0.2
.
x0 = 0.2;
Specify the one semi-infinite constraint.
ntheta = 1;
Solve the problem by calling fseminf
and view the result.
A = [];
b = [];
Aeq = [];
beq = [];
lb = 0;
ub = 2;
[x,fval,exitflag,output,lambda] = fseminf(objfun,x0,ntheta,@seminfcon,...
A,b,Aeq,beq,lb,ub)
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 0.5000
fval = 0.2500
exitflag = 1
output = struct with fields:
iterations: 2
funcCount: 4
lssteplength: 1
stepsize: 4.6841e-12
algorithm: 'active-set'
firstorderopt: 9.3682e-12
constrviolation: 4.6841e-12
message: 'Local minimum found that satisfies the constraints....'
lambda = struct with fields:
lower: 0
upper: 0
eqlin: [0x1 double]
eqnonlin: [0x1 double]
ineqlin: [0x1 double]
ineqnonlin: [1x0 double]
The returned values show:
The problem is solved at .
The value of the objective function, , is .
The solver takes two iterations and four function evaluations to reach the solution.
The only constraints other than semi-infinite constraints are bounds, so the
lambda
structure has no linear or nonlinear values. Thelambda.lower
andlambda.upper
fields, which correspond to bounds, are not empty, but have zero values because the solution is not at either bound.
The following code creates the seminfcon
function.
function [c, ceq, K1, s] = seminfcon(x,s) % No finite nonlinear inequality and equality constraints c = []; ceq = []; % Sample set if isnan(s) % Initial sampling interval s = [0.01 0]; end t = 0:s(1):1; % Evaluate the semi-infinite constraint K1 = (x - 0.5) - (t - 0.5).^2; end
Input Arguments
fun
— Function to minimize
function handle | function name
Function to minimize, specified as a function handle or function name.
fun
is a function that accepts a vector or array
x
and returns a real scalar f
, the objective
function evaluated at x
.
fseminf
passes x
to
your objective function and any nonlinear constraint functions in the shape of the
x0
argument. For example, if x0
is a 5-by-3 array,
then fseminf
passes x
to fun
as a
5-by-3 array. However, fseminf
multiplies linear constraint matrices
A
or Aeq
with x
after
converting x
to the column vector x(:)
.
Specify fun
as a function handle for a file.
x = fseminf(@myfun,...)
Here, myfun
is a MATLAB® function such as the following.
function f = myfun(x) f = ... % Compute function value at x
You can also specify fun
as a function handle for an anonymous
function.
x = fseminf(@(x)norm(x)^2,...);
If you can compute the gradient of fun
and the SpecifyObjectiveGradient
option is set
to true
, as set
by
options = optimoptions('fseminf','SpecifyObjectiveGradient',true);
fun
must return the gradient vector g(x)
in the
second output argument.
Example: fun = @(x)sin(x(1))*cos(x(2))
Data Types: char
| function_handle
| string
x0
— Initial point
real vector | real array
Initial point, specified as a real vector or real array. Solvers use the number of elements in
x0
and the size of x0
to determine the number
and size of variables that fun
accepts.
Example: x0 = [1,2,3,4]
Data Types: double
ntheta
— Number of semi-infinite constraints
positive integer
Number of semi-infinite constraints, specified as a positive integer.
Example: 4
Data Types: double
seminfcon
— Function that computes nonlinear constraints and semi-infinite constraints
function handle | function name
Function that computes the vector of nonlinear inequality constraints
c
, the vector of nonlinear equality constraints
ceq
, and ntheta
semi-infinite constraints
(vectors or matrices) K1
,
K2
,...
, Kntheta
evaluated
over an interval S
at the point x
. You can specify
seminfcon
as a function handle.
x = fseminf(@myfun,x0,ntheta,@myinfcon)
where myinfcon
is a MATLAB function such as
function [c,ceq,K1,K2,...,Kntheta,S] = myinfcon(x,S) % Initial sampling interval if isnan(S(1,1)), S = ...% S has ntheta rows and 2 columns end w1 = ...% Compute sample set w2 = ...% Compute sample set ... wntheta = ... % Compute sample set K1 = ... % 1st semi-infinite constraint at x and w K2 = ... % 2nd semi-infinite constraint at x and w ... Kntheta = ...% Last semi-infinite constraint at x and w c = ... % Compute nonlinear inequalities at x ceq = ... % Compute nonlinear equalities at x
S
is a recommended sampling interval, which the function might
not use. Return []
for c
and
ceq
if no such constraints exist.
The vectors or matrices K1
, K2
,
...
, Kntheta
contain the semi-infinite
constraints evaluated for a sampled set of values for the independent variables
w1
, w2
, ...
,
wntheta
, respectively. The two-column matrix S
contains a recommended sampling interval for values of w1
,
w2
, ...
, wntheta
, which are
used to evaluate K1
, K2
, ...
,
Kntheta
. The i
th row of S
contains the recommended sampling interval for evaluating
K
i
. When
K
i
is a vector, the
function uses only S(i,1)
(the second column can be all zeros). When
K
i
is a matrix, the
function uses S(i,2)
to sample the rows in
K
i
, and uses
S(i,1)
for the sampling interval of the columns of
K
i
(see Two-Dimensional Semi-Infinite Constraint). Because S
is
NaN
on the first iteration, seminfcon
must
determine some initial sampling interval.
Note
Because Optimization Toolbox™ functions accept inputs of type double
only,
user-supplied objective and nonlinear constraint functions must return outputs of type
double
.
For methods to parameterize seminfcon
, if necessary, see Passing Extra Parameters. For an example of both one- and two-dimensional
sampling points, see Example of Creating Sampling Points.
A
— Linear inequality constraints
real matrix
Linear inequality constraints, specified as a real matrix. A
is
an M
-by-N
matrix, where M
is
the number of inequalities, and N
is the number
of variables (number of elements in x0
). For
large problems, pass A
as a sparse matrix.
A
encodes the M
linear
inequalities
A*x <= b
,
where x
is the column vector of N
variables x(:)
,
and b
is a column vector with M
elements.
For example, consider these inequalities:
x1 + 2x2 ≤
10
3x1 +
4x2 ≤ 20
5x1 +
6x2 ≤ 30,
Specify the inequalities by entering the following constraints.
A = [1,2;3,4;5,6]; b = [10;20;30];
Example: To specify that the x components sum to 1 or less, use A =
ones(1,N)
and b = 1
.
Data Types: double
b
— Linear inequality constraints
real vector
Linear inequality constraints, specified as a real vector. b
is
an M
-element vector related to the A
matrix.
If you pass b
as a row vector, solvers internally
convert b
to the column vector b(:)
.
For large problems, pass b
as a sparse vector.
b
encodes the M
linear
inequalities
A*x <= b
,
where x
is the column vector of N
variables x(:)
,
and A
is a matrix of size M
-by-N
.
For example, consider these inequalities:
x1
+ 2x2 ≤
10
3x1
+ 4x2 ≤
20
5x1
+ 6x2 ≤
30.
Specify the inequalities by entering the following constraints.
A = [1,2;3,4;5,6]; b = [10;20;30];
Example: To specify that the x components sum to 1 or less, use A =
ones(1,N)
and b = 1
.
Data Types: double
Aeq
— Linear equality constraints
real matrix
Linear equality constraints, specified as a real matrix. Aeq
is
an Me
-by-N
matrix, where Me
is
the number of equalities, and N
is the number of
variables (number of elements in x0
). For large
problems, pass Aeq
as a sparse matrix.
Aeq
encodes the Me
linear
equalities
Aeq*x = beq
,
where x
is the column vector of N
variables x(:)
,
and beq
is a column vector with Me
elements.
For example, consider these inequalities:
x1 + 2x2 +
3x3 = 10
2x1 +
4x2 + x3 =
20,
Specify the inequalities by entering the following constraints.
Aeq = [1,2,3;2,4,1]; beq = [10;20];
Example: To specify that the x components sum to 1, use Aeq = ones(1,N)
and
beq = 1
.
Data Types: double
beq
— Linear equality constraints
real vector
Linear equality constraints, specified as a real vector. beq
is
an Me
-element vector related to the Aeq
matrix.
If you pass beq
as a row vector, solvers internally
convert beq
to the column vector beq(:)
.
For large problems, pass beq
as a sparse vector.
beq
encodes the Me
linear
equalities
Aeq*x = beq
,
where x
is the column vector of N
variables
x(:)
, and Aeq
is a matrix of size
Me
-by-N
.
For example, consider these equalities:
x1
+ 2x2 +
3x3 =
10
2x1
+ 4x2 +
x3 =
20.
Specify the equalities by entering the following constraints.
Aeq = [1,2,3;2,4,1]; beq = [10;20];
Example: To specify that the x components sum to 1, use Aeq = ones(1,N)
and
beq = 1
.
Data Types: double
lb
— Lower bounds
real vector | real array
Lower bounds, specified as a real vector or real array. If the number of elements in
x0
is equal to the number of elements in lb
,
then lb
specifies that
x(i) >= lb(i)
for all i
.
If numel(lb) < numel(x0)
, then lb
specifies
that
x(i) >= lb(i)
for 1 <=
i <= numel(lb)
.
If lb
has fewer elements than x0
, solvers issue a
warning.
Example: To specify that all x components are positive, use lb =
zeros(size(x0))
.
Data Types: double
ub
— Upper bounds
real vector | real array
Upper bounds, specified as a real vector or real array. If the number of elements in
x0
is equal to the number of elements in ub
,
then ub
specifies that
x(i) <= ub(i)
for all i
.
If numel(ub) < numel(x0)
, then ub
specifies
that
x(i) <= ub(i)
for 1 <=
i <= numel(ub)
.
If ub
has fewer elements than x0
, solvers issue
a warning.
Example: To specify that all x components are less than 1, use ub =
ones(size(x0))
.
Data Types: double
options
— Optimization options
output of optimoptions
| structure such as optimset
returns
Optimization options, specified as the output of optimoptions
or a structure such as optimset
returns. See Optimization Options Reference for detailed information.
Some options are absent from the
optimoptions
display. These options appear in italics in the following
table. For details, see View Optimization Options.
Option | Description |
---|---|
| Compare user-supplied derivatives (gradients of
objective or constraints) to finite-differencing derivatives. The choices are
For The |
ConstraintTolerance | Termination tolerance on the constraint
violation (a positive scalar). The default is For |
Diagnostics | Display diagnostic information about the
function to be minimized or solved. The choices are |
DiffMaxChange | Maximum change in variables for
finite-difference gradients (a positive scalar). The default is
|
DiffMinChange | Minimum change in variables for
finite-difference gradients (a positive scalar). The default is
|
Display | Level of display (see Iterative Display):
|
FiniteDifferenceStepSize |
Scalar or vector step size factor for finite differences. When
you set
sign′(x) = sign(x) except sign′(0) = 1 .
Central finite differences are
FiniteDifferenceStepSize expands to a vector. The default
is sqrt(eps) for forward finite differences, and eps^(1/3)
for central finite differences.
For |
FiniteDifferenceType | Finite differences, used to estimate gradients,
are either The algorithm is careful to obey bounds when estimating both types of finite differences. For example, to avoid evaluating at a point outside the bounds, the algorithm might take a backward difference rather than a forward difference. For |
FunctionTolerance | Termination tolerance on the function value (a
positive scalar). The default is For
|
FunValCheck | Check whether objective function and
constraints values are valid. The setting |
MaxFunctionEvaluations | Maximum number of function evaluations allowed
(a positive integer). The default is For
|
MaxIterations | Maximum number of iterations allowed (a
positive integer). The default is For
|
MaxSQPIter | Maximum number of SQP iterations allowed (a
positive integer). The default is |
OptimalityTolerance | Termination tolerance on the first-order optimality (a positive
scalar). The default is For |
OutputFcn | Specify one or more user-defined functions
called by an optimization function at each iteration. Pass a function handle
or a cell array of function handles. The default is none
( |
PlotFcn | Plot various measures of progress while the
algorithm executes; select from predefined plots or write your own. Pass a
name, function handle, or cell array of names or function handles. For custom
plot functions, pass function handles. The default is none
(
Custom plot functions use the same syntax as output functions. See Output Functions for Optimization Toolbox and Output Function and Plot Function Syntax. For |
RelLineSrchBnd | Relative bound (a real nonnegative scalar
value) on the line search step length such that the total displacement in
|
RelLineSrchBndDuration | Number of iterations for which the bound
specified in |
SpecifyObjectiveGradient | Gradient for the objective function defined by
the user. See the preceding description of For
|
StepTolerance | Termination tolerance on For
|
TolConSQP | Termination tolerance on the inner iteration
SQP constraint violation, a positive scalar. The default is
|
TypicalX | Typical |
Example: options =
optimoptions('fseminf','PlotFcn','optimplotfval')
problem
— Problem structure
structure
Problem structure, specified as a structure with the following fields.
Field Name | Entry |
---|---|
| Objective function |
| Initial point for x |
| Number of semi-infinite constraints |
| Semi-infinite constraint function |
| Matrix for linear inequality constraints |
| Vector for linear inequality constraints |
| Matrix for linear equality constraints |
| Vector for linear equality constraints |
lb | Vector of lower bounds |
ub | Vector of upper bounds |
| 'fmseminf' |
| Options created with optimoptions |
You must supply at least the objective
, x0
,
seminfcon
, solver
, and
options
fields in the problem
structure.
Data Types: struct
Output Arguments
x
— Solution
real vector | real array
Solution, returned as a real vector or real array. The size
of x
is the same as the size of x0
.
Typically, x
is a local solution to the problem
when exitflag
is positive. For information on
the quality of the solution, see When the Solver Succeeds.
fval
— Objective function value at solution
real number
Objective function value at the solution, returned as a real
number. Generally, fval
= fun(x)
.
exitflag
— Reason fseminf
stopped
integer
Reason fseminf
stopped, returned as an integer.
Flag | Description |
---|---|
| Function converged to a solution |
| Magnitude of the search direction was less than the specified
tolerance, and the constraint violation was less than
|
| Magnitude of the directional derivative was less than the specified
tolerance, and the constraint violation was less than
|
| Number of iterations exceeded
|
| Stopped by an output function or plot function. |
| No feasible point was found. |
output
— Information about the optimization process
structure
Information about the optimization process, returned as a structure with the following fields.
Field Name | Description |
---|---|
iterations | Number of iterations taken |
funcCount | Number of function evaluations |
lssteplength | Size of line search step relative to search direction |
stepsize | Final displacement in |
algorithm | Optimization algorithm used |
constrviolation | Maximum of constraint functions |
firstorderopt | Measure of first-order optimality |
message | Exit message |
iterations | Number of iterations taken |
funcCount | Number of function evaluations |
lambda
— Lagrange multipliers at the solution
structure
Lagrange multipliers at the solution, returned as a structure with the following fields.
Limitations
The function to be minimized, the constraints, and the semi-infinite constraints must be continuous functions of
x
andw
.fseminf
might give local solutions only.
Algorithms
fseminf
uses cubic and quadratic interpolation techniques to estimate
peak values in the semi-infinite constraints. The algorithm uses the peak values to form a set
of constraints supplied to an SQP method, as in the fmincon
function. When the number of constraints changes, the algorithm
reallocates Lagrange multipliers to the new set of constraints.
The recommended sampling interval calculation uses the difference between the interpolated peak values and the peak values in the data set to estimate whether the function needs to take more or fewer points. The function also evaluates the effectiveness of the interpolation by extrapolating the curve and comparing it to other points in the curve. The recommended sampling interval decreases when the peak values are close to constraint boundaries, that is, zero.
When the problem is not feasible, fseminf
attempts to minimize the
maximum constraint value.
For more details on the algorithm used and the types of procedures displayed under the
Procedures
heading when the Display
option is set to
'iter'
with optimoptions
, see SQP Implementation. For more details on the fseminf
algorithm,
see fseminf Problem Formulation and Algorithm.
Version History
Introduced before R2006aR2023b: CheckGradients
option will be removed
The CheckGradients
option will be removed in a future release. To check the first derivatives of objective functions or nonlinear constraint functions, use the checkGradients
function.
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other bat365 country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)