f[x_, y_] := a (Cos[x] + Cos[y]) + b (Cos[2 x] + Cos[2 y]) + c (Cos[x] Cos[y])
(* Determine where partial derivatives are zero *)
extrema = {x, y, f[x, y]} /. Solve[D[f[x, y], {{x, y}}] == 0, {x, y}] /. C[1] -> 0 /. C[2] -> 0 // FullSimplify
(* Find minima and maxima for specific values of a, b, and c *)
minmax[aa_, bb_, cc_] := Module[{e, minima, maxima},
e = extrema /. {a -> aa, b -> bb, c -> cc};
minima = Select[e, #[[3]] == Min[e[[All, 3]]] &];
maxima = Select[e, #[[3]] == Max[e[[All, 3]]] &];
{minima, maxima}]
{minima, maxima} = minmax[10, -7, 4]
(* {{{π, π, -30}},
{{-ArcTan[Sqrt[119]/5], -ArcTan[Sqrt[119]/5], 109/6},
{-ArcTan[Sqrt[119]/5], ArcTan[Sqrt[119]/5], 109/6},
{ ArcTan[Sqrt[119]/5], -ArcTan[Sqrt[119]/5], 109/6},
{ ArcTan[Sqrt[119]/5], ArcTan[Sqrt[119]/5], 109/6}}} *)
Finding solutions in general
There are only 6 unique extrema values/forumulas:
(* Determine where partial derivatives are zero *)
extrema = {x, y, f[x, y]} /. Solve[D[f[x, y], {{x, y}}] == 0, {x, y}] // FullSimplify
(unique = FullSimplify[DeleteDuplicates[extrema[[All, 3]]],
Assumptions -> C[1] ∈ Integers && C[2] ∈ Integers]) // TableForm
(Note that I dropped the restriction /. C[1] -> 0 /. C[2] -> 0
.)
The first value in unique
is the global maximum when the following occurs:
Reduce[Table[unique[[1]] >= unique[[i]], {i, 2, 6}]]
In this same fashion one can determine when each unique formula is the global minimum, global maximum, local minimum, or local maximum. It does not appear that a general solution will be short and sweet.
Getting to know the function
Here is some Manipulate
code that shows the global minimum and maximum location(s) along with other points where the first partial derivatives are zero:
f[x_, y_, a_, b_, c_] :=
a (Cos[x] + Cos[y]) + b (Cos[2 x] + Cos[2 y]) + c (Cos[x] Cos[y])
Manipulate[
extrema = {x, y, f[x, y, a, b, c]} /.
Solve[D[f[x, y, a, b, c], {{x, y}}] == 0, {x, y}, Reals] /.
C[1] -> c1 /. C[2] -> c2 // FullSimplify // Quiet;
extrema =
Flatten[Table[Table[extrema[[i]], {c1, -1, 1}, {c2, -1, 1}], {i, Length[extrema]}], 2];
extrema = Select[extrema, -π <= #[[1]] <= π && -π <= #[[2]] <= π &];
maxima = Select[extrema, #[[3]] == Max[extrema[[All, 3]]] &];
minima = Select[extrema, #[[3]] == Min[extrema[[All, 3]]] &];
Show[ContourPlot[f[x, y, a, b, c], {x, -π, π}, {y, -π, π}, ContourShading -> None],
ListPlot[{extrema[[All, {1, 2}]], maxima[[All, {1, 2}]], minima[[All, {1, 2}]]},
PlotStyle -> {LightGray, Black, Red},
PlotLegends -> {"Other", "Global maximum", "Global minimum"}]],
{{a, 6}, -10, 10, Appearance -> "Labeled"},
{{b, 1}, -10, 10, Appearance -> "Labeled"},
{{c, -7}, -10, 10, Appearance -> "Labeled"},
TrackedSymbols :> {a, b, c}]
Maximize
andMinimize
? $\endgroup$