%% Solve Minimax Problem Using Absolute Value of One Objective
% fminimax can minimize the maximum of either F_i(x) or |F_i(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 F_1(x) through F_k(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.

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)

% Try starting from x0 = –2.

x0 = -2;
x2 = fminimax(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)

% Plot the function.

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.
% Copyright 2018 The MathWorks, Inc.