%% Minimize Maximum of sin and cos
% Create a plot of the sin and cos functions and their maximum over the interval [–pi,pi].

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.

fun = @(x)[sin(x);cos(x)];
x0 = 1;
x1 = fminimax(fun,x0)

% Find the minimum near –2.

x0 = -2;
x2 = fminimax(fun,x0)

% Copyright 2018 The MathWorks, Inc.