Main Content

fseminf

Find minimum of semi-infinitely constrained multivariable nonlinear function

Description

fseminf is a nonlinear programming solver that finds the minimum of a problem specified by

minxf(x) such that {Axb,Aeqx=beq,lbxub,c(x)0,ceq(x)=0,Ki(x,wi)0, 1in.

  • 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.

example

x = fseminf(fun,x0,ntheta,seminfcon) starts at x0 and finds a minimum of the function fun constrained by ntheta semi-infinite constraints defined in seminfcon.

x = fseminf(fun,x0,ntheta,seminfcon,A,b) also tries to satisfy the linear inequalities A*x ≤ b.

x = fseminf(fun,x0,ntheta,seminfcon,A,b,Aeq,beq) minimizes subject to the linear equalities Aeq*x = beq as well. Set A = [] and b = [] if no inequalities exist.

x = fseminf(fun,x0,ntheta,seminfcon,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds on the design variables in x, so that the solution is always in the range lb  x  ub.

x = fseminf(fun,x0,ntheta,seminfcon,A,b,Aeq,beq,lb,ub,options) minimizes with the optimization options specified in options. Use optimoptions to set these options.

x = fseminf(problem) finds the minimum for problem, a structure described in problem.

[x,fval] = fseminf(___), for any previous input syntax, returns the value of the objective function fun at the solution x.

Note

If the specified input bounds for a problem are inconsistent, the output x is x0 and the output fval is [].

example

[x,fval,exitflag,output] = fseminf(___) also returns a value exitflag that describes the exit condition, and a structure output with information about the optimization process.

example

[x,fval,exitflag,output,lambda] = fseminf(___) returns a structure lambda whose fields contain the Lagrange multipliers at the solution x.

Examples

collapse all

Minimize the function

(x-1)2,

subject to the constraints

0x2

g(x,t)=(x-1/2)-(t-1/2)20 for all 0t1.

The unconstrained objective function is minimized at x=1. However, the constraint

g(x,t)0 for all 0t1

implies x1/2. Notice that (t-1/2)20, so

maxtg(x,t)=x-1/2.

Therefore,

maxtg(x,t)0 when x1/2.

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 t (0 to 1 in steps of 0.01), and the semi-infinite constraint function g(x,t). 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

Minimize the function

(x-1)2,

subject to the constraints

0x2

g(x,t)=(x-1/2)-(t-1/2)20 for all 0t1.

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 x=1/2.

  • The value of the objective function, (x-1)2, is 1/4.

  • 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. The lambda.lower and lambda.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

collapse all

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);
then 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

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

Number of semi-infinite constraints, specified as a positive integer.

Example: 4

Data Types: double

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 ith row of S contains the recommended sampling interval for evaluating Ki. When Ki is a vector, the function uses only S(i,1) (the second column can be all zeros). When Ki is a matrix, the function uses S(i,2) to sample the rows in Ki, and uses S(i,1) for the sampling interval of the columns of Ki (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.

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

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

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

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

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

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

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.

OptionDescription

CheckGradients

Compare user-supplied derivatives (gradients of objective or constraints) to finite-differencing derivatives. The choices are true or the default false.

For optimset, the name is DerivativeCheck and the values are 'on' or 'off'. See Current and Legacy Option Names.

The CheckGradients option will be removed in a future release. To check derivatives, use the checkGradients function.

ConstraintTolerance

Termination tolerance on the constraint violation (a positive scalar). The default is 1e-6. See Tolerances and Stopping Criteria.

For optimset, the name is TolCon. See Current and Legacy Option Names.

Diagnostics

Display diagnostic information about the function to be minimized or solved. The choices are 'on' or the default 'off'.

DiffMaxChange

Maximum change in variables for finite-difference gradients (a positive scalar). The default is Inf.

DiffMinChange

Minimum change in variables for finite-difference gradients (a positive scalar). The default is 0.

Display

Level of display (see Iterative Display):

  • 'off' or 'none' displays no output.

  • 'iter' displays output at each iteration, and gives the default exit message.

  • 'iter-detailed' displays output at each iteration, and gives the technical exit message.

  • 'notify' displays output only if the function does not converge, and gives the default exit message.

  • 'notify-detailed' displays output only if the function does not converge, and gives the technical exit message.

  • 'final' (default) displays only the final output, and gives the default exit message.

  • 'final-detailed' displays only the final output, and gives the technical exit message.

FiniteDifferenceStepSize

Scalar or vector step size factor for finite differences. When you set FiniteDifferenceStepSize to a vector v, the forward finite differences delta are

delta = v.*sign′(x).*max(abs(x),TypicalX);

where sign′(x) = sign(x) except sign′(0) = 1. Central finite differences are

delta = v.*max(abs(x),TypicalX);

A scalar FiniteDifferenceStepSize expands to a vector. The default is sqrt(eps) for forward finite differences, and eps^(1/3) for central finite differences.

For optimset, the name is FinDiffRelStep. See Current and Legacy Option Names.

FiniteDifferenceType

Finite differences, used to estimate gradients, are either 'forward' (the default) or 'central' (centered). 'central' takes twice as many function evaluations, but can be more accurate.

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 optimset, the name is FinDiffType. See Current and Legacy Option Names.

FunctionTolerance

Termination tolerance on the function value (a positive scalar). The default is 1e-4. See Tolerances and Stopping Criteria.

For optimset, the name is TolFun. See Current and Legacy Option Names.

FunValCheck

Check whether objective function and constraints values are valid. The setting 'on' displays an error when the objective function or constraints return a value that is complex, Inf, or NaN. The default 'off' displays no error.

MaxFunctionEvaluations

Maximum number of function evaluations allowed (a positive integer). The default is 100*numberOfVariables. See Tolerances and Stopping Criteria and Iterations and Function Counts.

For optimset, the name is MaxFunEvals. See Current and Legacy Option Names.

MaxIterations

Maximum number of iterations allowed (a positive integer). The default is 400. See Tolerances and Stopping Criteria and Iterations and Function Counts.

For optimset, the name is MaxIter. See Current and Legacy Option Names.

MaxSQPIter

Maximum number of SQP iterations allowed (a positive integer). The default is 10*max(numberOfVariables, numberOfInequalities + numberOfBounds).

OptimalityTolerance

Termination tolerance on the first-order optimality (a positive scalar). The default is 1e-6. See First-Order Optimality Measure.

For optimset, the name is TolFun. See Current and Legacy Option Names.

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 ([]). See Output Function and Plot Function Syntax.

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 ([]).

  • 'optimplotx' plots the current point.

  • 'optimplotfunccount' plots the function count.

  • 'optimplotfval' plots the function value.

  • 'optimplotfvalconstr' plots the best feasible objective function value found as a line plot. The plot shows infeasible points in one color and feasible points in another, using a feasibility tolerance of 1e-6.

  • 'optimplotconstrviolation' plots the maximum constraint violation.

  • 'optimplotstepsize' plots the step size.

  • 'optimplotfirstorderopt' plots the first-order optimality measure.

Custom plot functions use the same syntax as output functions. See Output Functions for Optimization Toolbox and Output Function and Plot Function Syntax.

For optimset, the name is PlotFcns. See Current and Legacy Option Names.

RelLineSrchBnd

Relative bound (a real nonnegative scalar value) on the line search step length such that the total displacement in x satisfies x(i)| ≤ relLineSrchBnd· max(|x(i)|,|typicalx(i)|). This option provides control over the magnitude of the displacements in x for cases in which the solver takes steps that fseminf considers too large. The default is no bounds ([]).

RelLineSrchBndDuration

Number of iterations for which the bound specified in RelLineSrchBnd should be active (default is 1).

SpecifyObjectiveGradient

Gradient for the objective function defined by the user. See the preceding description of fun to see how to define the gradient in fun. Set this option to true to have fseminf use a user-defined gradient of the objective function. The default false causes fseminf to estimate gradients using finite differences.

For optimset, the name is GradObj and the values are 'on' or 'off'. See Current and Legacy Option Names.

StepTolerance

Termination tolerance on x, a positive scalar. The default value is 1e-4. See Tolerances and Stopping Criteria.

For optimset, the name is TolX. See Current and Legacy Option Names.

TolConSQP

Termination tolerance on the inner iteration SQP constraint violation, a positive scalar. The default is 1e-6.

TypicalX

Typical x values. The number of elements in TypicalX is equal to the number of elements in x0, the starting point. The default value is ones(numberofvariables,1). fseminf uses TypicalX for scaling finite differences for gradient estimation.

Example: options = optimoptions('fseminf','PlotFcn','optimplotfval')

Problem structure, specified as a structure with the following fields.

Field NameEntry

objective

Objective function

x0

Initial point for x

ntheta

Number of semi-infinite constraints

seminfcon

Semi-infinite constraint function

Aineq

Matrix for linear inequality constraints

bineq

Vector for linear inequality constraints

Aeq

Matrix for linear equality constraints

beq

Vector for linear equality constraints
lbVector of lower bounds
ubVector of upper bounds

solver

'fmseminf'

options

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

collapse all

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.

Objective function value at the solution, returned as a real number. Generally, fval = fun(x).

Reason fseminf stopped, returned as an integer.

Flag

Description

1

Function converged to a solution x.

4

Magnitude of the search direction was less than the specified tolerance, and the constraint violation was less than options.ConstraintTolerance.

5

Magnitude of the directional derivative was less than the specified tolerance, and the constraint violation was less than options.ConstraintTolerance.

0

Number of iterations exceeded options.MaxIterations, or the number of function evaluations exceeded options.MaxFunctionEvaluations.

-1

Stopped by an output function or plot function.

-2

No feasible point was found.

Information about the optimization process, returned as a structure with the following fields.

Field NameDescription
iterations

Number of iterations taken

funcCount

Number of function evaluations

lssteplength

Size of line search step relative to search direction

stepsize

Final displacement in x

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

Lagrange multipliers at the solution, returned as a structure with the following fields.

Field NameDescription
lower

Lower bounds corresponding to lb

upper

Upper bounds corresponding to ub

ineqlin

Linear inequalities corresponding to A and b

eqlin

Linear equalities corresponding to Aeq and beq

ineqnonlin

Nonlinear inequalities corresponding to the c in seminfcon

eqnonlin

Nonlinear equalities corresponding to the ceq in seminfcon

Limitations

  • The function to be minimized, the constraints, and the semi-infinite constraints must be continuous functions of x and w.

  • 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 R2006a

expand all