Fminimax
Fminimax
x = fminimax(fun,x0)
x = fminimax(fun,x0,A,b)
x = fminimax(fun,x0,A,b,Aeq,beq)
x = fminimax(fun,x0,A,b,Aeq,beq,lb,ub)
x = fminimax(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
x = fminimax(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
x = fminimax(problem)
[x,fval] = fminimax(___)
[x,fval,maxfval,exitflag,output] = fminimax(___)
[x,fval,maxfval,exitflag,output,lambda] = fminimax(___)
Description
fminimax seeks a point that minimizes the maximum of a set of objective functions.
The problem includes any type of constraint. In detail, fminimax seeks the minimum of a
problem specified by
where b and beq are vectors, A and Aeq are matrices, and c(x), ceq(x), and F(x) are
functions that return vectors. F(x), c(x), and ceq(x) can be nonlinear functions.
You can also solve max-min problems with fminimax, using the identity
maxxminiFi(x)=−minxmaxi(−Fi(x)).
You can solve problems of the form
minxmaxi∣Fi(x)∣
example
example
Note
Note
If the specified input bounds for a problem are inconsistent, the output x is x0 and the
output fval is [].
example
example
example
[x,fval] = fminimax(___), for any syntax, returns the values of the objective functions
computed in fun at the solution x.
example
[x,fval,maxfval,exitflag,output] = fminimax(___) additionally returns the maximum value
of the objective functions at the solution x, a value exitflag that describes the exit
condition of fminimax, and a structure output with information about the optimization
process.
example
Examples
collapse all
Minimize Maximum of sin and cos
Create a plot of the sin and cos functions and their maximum over the interval [–pi,pi].
Get
t = linspace(-pi,pi);
plot(t,sin(t),'r-')
hold on
plot(t,cos(t),'b-');
plot(t,max(sin(t),cos(t)),'ko')
legend('sin(t)','cos(t)','max(sin(t),cos(t))','Location','NorthWest')
The plot shows two local minima of the maximum, one near 1, and the other near –2.
Find the minimum near 1.
Get
fun = @(x)[sin(x);cos(x)];
x0 = 1;
x1 = fminimax(fun,x0)
Local minimum possible. Constraints satisfied.
fminimax stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are
x1 =
0.7854
Find the minimum near –2.
Get
x0 = -2;
x2 = fminimax(fun,x0)
Local minimum possible. Constraints satisfied.
fminimax stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are
x2 =
-2.3562
The objective functions for this example are linear plus constants. For a description and
plot of the objective functions, see Compare fminimax and fminunc.
Set the objective functions as three linear functions of the form dot(x,v)+v0 for three
vectors v and three constants v0.
Get
a = [1;1];
b = [-1;1];
c = [0;-1];
a0 = 2;
b0 = -3;
c0 = 4;
fun = @(x)[x*a+a0,x*b+b0,x*c+c0];
Find the minimax point subject to the inequality x(1) + 3*x(2) <= –4.
Get
A = [1,3];
b = -4;
x0 = [-1,-2];
x = fminimax(fun,x0,A,b)
fminimax stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are
x = 1×2
-5.8000 0.6000
The objective functions for this example are linear plus constants. For a description and
plot of the objective functions, see Compare fminimax and fminunc.
Set the objective functions as three linear functions of the form dot(x,v)+v0 for three
vectors v and three constants v0.
Get
a = [1;1];
b = [-1;1];
c = [0;-1];
a0 = 2;
b0 = -3;
c0 = 4;
fun = @(x)[x*a+a0,x*b+b0,x*c+c0];
Set bounds that –2 <= x(1) <= 2 and –1 <= x(2) <= 1 and solve the minimax problem
starting from [0,0].
Get
lb = [-2,-1];
ub = [2,1];
x0 = [0,0];
A = []; % No linear constraints
b = [];
Aeq = [];
beq = [];
[x,fval] = fminimax(fun,x0,A,b,Aeq,beq,lb,ub)
fminimax stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are
x = 1×2
-0.0000 1.0000
fval = 1×3
In this case, the solution is not unique. Many points satisfy the constraints and have the
same minimax value. Plot the surface representing the maximum of the three objective
functions, and plot a red line showing the points that have the same minimax value.
Get
[X,Y] = meshgrid(linspace(-2,2),linspace(-1,1));
Z = max(fun([X(:),Y(:)]),[],2);
Z = reshape(Z,size(X));
surf(X,Y,Z,'LineStyle','none')
view(-118,28)
hold on
line([-2,0],[1,1],[3,3],'Color','r','LineWidth',8)
hold off
The objective functions for this example are linear plus constants. For a description and
plot of the objective functions, see Compare fminimax and fminunc.
Set the objective functions as three linear functions of the form dot(x,v)+v0 for three
vectors v and three constants v0.
Get
a = [1;1];
b = [-1;1];
c = [0;-1];
a0 = 2;
b0 = -3;
c0 = 4;
fun = @(x)[x*a+a0,x*b+b0,x*c+c0];
Get
type unitdisk
c = x(1)^2 + x(2)^2 - 1;
ceq = [];
Solve the minimax problem subject to the unitdisk constraint, starting from x0 = [0,0].
Get
x0 = [0,0];
b = [];
Aeq = [];
beq = [];
lb = [];
ub = [];
nonlcon = @unitdisk;
x = fminimax(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
fminimax stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are
satisfied to within the value of the constraint tolerance.
x = 1×2
-0.0000 1.0000
fminimax can minimize the maximum of either Fi(x) or ∣Fi(x)∣ for the first several values
of i by using the AbsoluteMaxObjectiveCount option. To minimize the absolute values
of k of the objectives, arrange the objective function values so
that F1(x) through Fk(x) are the objectives for absolute minimization, and set
the AbsoluteMaxObjectiveCount option to k.
In this example, minimize the maximum of sin and cos, specify sin as the first objective,
and set AbsoluteMaxObjectiveCount to 1.
Get
fun = @(x)[sin(x),cos(x)];
options = optimoptions('fminimax','AbsoluteMaxObjectiveCount',1);
x0 = 1;
A = []; % No constraints
b = [];
Aeq = [];
beq = [];
lb = [];
ub = [];
nonlcon = [];
x1 = fminimax(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
fminimax stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are
x1 =
0.7854
Try starting from x0 = –2.
Get
x0 = -2;
x2 = fminimax(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
fminimax stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are
satisfied to within the value of the constraint tolerance.
x2 =
-3.1416
Get
t = linspace(-pi,pi);
plot(t,max(abs(sin(t)),cos(t)))
To see the effect of the AbsoluteMaxObjectiveCount option, compare this plot to the plot
in the example Minimize Maximum of sin and cos.
Obtain both the location of the minimax point and the value of the objective functions.
For a description and plot of the objective functions, see Compare fminimax and
fminunc.
Set the objective functions as three linear functions of the form dot(x,v)+v0 for three
vectors v and three constants v0.
Get
a = [1;1];
b = [-1;1];
c = [0;-1];
a0 = 2;
b0 = -3;
c0 = 4;
fun = @(x)[x*a+a0,x*b+b0,x*c+c0];
Set the initial point to [0,0] and find the minimax point and value.
Get
x0 = [0,0];
[x,fval] = fminimax(fun,x0)
fminimax stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are
-2.5000 2.2500
fval = 1×3
All three objective functions have the same value at the minimax point. Unconstrained
problems typically have at least two objectives that are equal at the solution, because if
a point is not a local minimum for any objective and only one objective has the
maximum value, then the maximum objective can be lowered.
Get
a = [1;1];
b = [-1;1];
c = [0;-1];
a0 = 2;
b0 = -3;
c0 = 4;
fun = @(x)[x*a+a0,x*b+b0,x*c+c0];
Find the minimax point subject to the inequality x(1) + 3*x(2) <= –4.
Get
A = [1,3];
b = -4;
x0 = [-1,-2];
Set options for iterative display, and obtain all solver outputs.
Get
options = optimoptions('fminimax','Display','iter');
beq = [];
lb = [];
ub = [];
nonlcon = [];
[x,fval,maxfval,exitflag,output,lambda] =...
fminimax(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
1 9 5 0 1 0.981
fminimax stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are
x = 1×2
-5.8000 0.6000
fval = 1×3
maxfval =
3.4000
exitflag =
4
output = struct with fields:
iterations: 4
funcCount: 19
lssteplength: 1
stepsize: 6.0684e-10
algorithm: 'active-set'
firstorderopt: []
constrviolation: 8.1323e-09
message: 'Local minimum possible. Constraints satisfied....'
ineqlin: 0.2000
ineqnonlin: [0x1 double]
• The lambda.ineqlin value is nonzero, indicating that the linear constraint is active
at the solution.
Input Arguments
collapse all
fun — Objective functions
function handle | function name
x = fminimax(@myfun,x0,goal,weight)
where myfun is a MATLAB® function such as
function F = myfun(x)
x = fminimax(@(x)sin(x.*x),x0,goal,weight);
fminimax 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 fminimax passes x to fun as a 5-by-3 array. However, fminimax multiplies linear
constraint matrices A or Aeq with x after converting x to the column vector x(:).
To minimize the worst-case absolute values of some elements of the vector F(x) (that is,
min{max abs{F(x)} } ), partition those objectives into the first elements of F and
use optimoptions to set the AbsoluteMaxObjectiveCount option to the number of these
objectives. These objectives must be partitioned into the first elements of the
vector F returned by fun. For an example, see Solve Minimax Problem Using Absolute
Value of One Objective.
options = optimoptions('fminimax','SpecifyObjectiveGradient',true)
In this case, the function fun must return, in the second output argument, the gradient
values G (a matrix) at x. The gradient consists of the partial derivative dF/dx of
each F at the point x. If F is a vector of length m and x has length n, where n is the
length of x0, then the gradient G of F(x) is an n-by-m matrix where G(i,j) is the partial
derivative of F(j) with respect to x(i) (that is, the jth column of G is the gradient of the jth
objective function F(j)). If you define F as an array, then the preceding discussion
applies to F(:), the linear ordering of the F array. In any case, G is a 2-D matrix.
Note
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]
x1 + 2x2 ≤ 10
3x1 + 4x2 ≤ 20
5x1 + 6x2 ≤ 30,
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.
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.
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.
Aeq*x = beq,
where x is the column vector of N variables x(:), and beq is a column vector
with Me elements.
x1 + 2x2 + 3x3 = 10
2x1 + 4x2 + x3 = 20,
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.
Aeq*x = beq,
where x is the column vector of N variables x(:), and Aeq is a matrix of size Me-by-N.
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: single | 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.
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
Example: To specify that all x components are less than 1, use ub = ones(size(x0)).
Data Types: single | double
For example,
x = fminimax(@myfun,x0,...,@mycon)
options = optimoptions('fminimax','SpecifyConstraintGradient',true)
In this case, the function nonlcon must also return, in the third and fourth output
arguments, GC, the gradient of c(x), and GCeq, the gradient of ceq(x). See Nonlinear
Constraints for an explanation of how to “conditionalize” the gradients for use in solvers
that do not accept supplied gradients.
If nonlcon returns a vector c of m components and x has length n, where n is the length
of x0, then the gradient GC of c(x) is an n-by-m matrix, where GC(i,j) is the partial
derivative of c(j) with respect to x(i) (that is, the jth column of GC is the gradient of
the jth inequality constraint c(j)). Likewise, if ceq has p components, the
gradient GCeq of ceq(x) is an n-by-p matrix, where GCeq(i,j) is the partial derivative
of ceq(j) with respect to x(i) (that is, the jth column of GCeq is the gradient of the jth
equality constraint ceq(j)).
Note
Note
Because Optimization Toolbox™ functions accept only inputs of type double,
user-supplied objective and nonlinear constraint functions must return outputs of
type double.
See Passing Extra Parameters for an explanation of how to parameterize the nonlinear
constraint function nonlcon, if necessary.
Some options are absent from the optimoptions display. These options appear in italics
in the following table. For details, see View Optimization Options.
For details about options that have different names for optimset, see Current and
Legacy Option Names.
Option Description
AbsoluteMaxObjectiveCount Number of elements of Fi(x) for which to minimize the absolute value of F
Objective.
• 'notify' displays output only if the function does not converge, and
• 'final' (default) displays only the final output, and gives the default
• 'final-detailed' displays only the final output, and gives the technic
FiniteDifferenceStepSize Scalar or vector step size factor for finite differences. When you set Finit
differences delta are
delta = v.*sign′(x).*max(abs(x),TypicalX);
delta = v.*max(abs(x),TypicalX);
A scalar FiniteDifferenceStepSize expands to a vector. The default is sqr
finite differences.
FiniteDifferenceType Type of finite differences used to estimate gradients, either 'forward' (def
function evaluations, but is generally more accurate.
FunValCheck Check that signifies whether the objective function and constraint values
constraints return a value that is complex, Inf, or NaN. The default 'off' di
MaxSQPIter Maximum number of SQP iterations allowed (a positive integer). The def
numberOfBounds).
MeritFunction If this option is set to 'multiobj' (the default), use the goal attainment or m
the fmincon merit function.
PlotFcn Plots showing various measures of progress while the algorithm execute
name, function handle, or cell array of names or function handles. For cu
none ([]).
Custom plot functions use the same syntax as output functions. See Out
Option Description
RelLineSrchBnd Relative bound (a real nonnegative scalar value) on the line search step
in x satisfies |Δx(i)| ≤ relLineSrchBnd· max(|x(i)|,|typicalx(i)|). This option
in x when the solver takes steps that are too large. The default is none ([
SpecifyConstraintGradient Gradient for nonlinear constraint functions defined by the user. When thi
to have four outputs, as described in nonlcon. When this option is set to
nonlinear constraints using finite differences.
For optimset, the name is GradConstr and the values are 'on' or 'off'.
SpecifyObjectiveGradient Gradient for the objective function defined by the user. Refer to the desc
to true to have fminimax use a user-defined gradient of the objective fun
gradients using finite differences.
For optimset, the name is GradObj and the values are 'on' or 'off'.
TypicalX Typical x values. The number of elements in TypicalX is equal to the num
is ones(numberofvariables,1). The fminimax function uses TypicalX for s
UseParallel Option for using parallel computing. When this option is set to true, fmini
See Parallel Computing.
Example: optimoptions('fminimax','PlotFcn','optimplotfval')
solver 'fminimax'
You must supply at least the objective, x0, solver, and options fields in
the problem structure.
Output Arguments
collapse all
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.
4 Magnitude of the search direction was less than the specified tolerance, and the constraint violation
5 Magnitude of the directional derivative was less than the specified tolerance, and the constraint vio
Information about the optimization process, returned as a structure with the fields in this
table.
lssteplength Size of the line search step relative to the search direction
Lagrange multipliers at the solution, returned as a structure with the fields in this table.