# Maximizing a function of two variables

I have the simple function:

$$\qquad f(x,a)=a\,x−ln(x/100)$$

with the constraints: $$0.1 < a < 1$$ and $$0.1 < x < 10$$

I want find the minimum of $$f(x,\,a)$$, assuming that the variable $$a$$ can take the worst value.

When I evaluated the following code

f[x_, a_] := a*x - Log[x/100];
Minimize[{f[x, a], 0.1 < x < 10, 0.1 < a < 1}, x]
Maximize[{%, 0.1 < x < 10, 0.1 < a < 1}, a]


I got

Maximize[
{Minimize[{a x - Log[x/100], 0.1 < x < 10, 0.1 < a < 1}, x],
0.1 < x < 10, 0.1 < a < 1}, a]


Any suggestions? -_-

Clear["Global*"]

f[x_, a_] := a*x - Log[x/100];


The minimum in the region is

min1 = Minimize[{f[x, a], 0.1 < x < 10, 0.1 < a < 1}, {a, x}]

(* {3.30259, {a -> 0.1, x -> 10.}} *)


The minimum for the worst case value of a is

min2 = Minimize[{f[x, a], 0.1 < x < 10, a == 1}, {a, x}]

(* {5.60517, {a -> 1., x -> 1.}} *)

ContourPlot[f[x, a], {x, 0.1, 10}, {a, 0.1, 1},
FrameLabel -> (Style[#, 14, Bold] & /@ {x, a}),
PlotLegends -> Automatic,
PlotLabel -> Style[f[x, a], 14, Bold], Epilog -> {AbsolutePointSize,
Green, Tooltip[Point[{x, a}], f[x, a]] /. min1[],
Red,
Tooltip[Point[{x, a}], f[x, a]] /. min2[]}] Show[
Plot3D[f[x, a], {x, 0.1, 10}, {a, 0.1, 1},
AxesLabel -> (Style[#, 14, Bold] & /@ {x, a, f})],
Graphics3D[{AbsolutePointSize,
Green, Point[{x, a, f[x, a]} /. min1[]],
Red,
Point[{x, a, f[x, a]} /. min2[]]}],
PlotLabel -> Style[f[x, a], 14, Bold],
ImageSize -> Medium] • Thanks for the answear, but I wanna know in general why my minimization problem doesn't work. This function is so simple that you see that a =1 is the worst case but with more complicated function is not possible that approach. Oct 17, 2020 at 14:01

It seems that at that time Minimize only work for concrete number.

Clear["*"];
f[x_, a_] := a*x - Log[x/100];
Table[Minimize[{f[x, a], 1/10 < x < 10 }, x], {a, 1/10, 1, 1/20}]


So we have to use D.

Since D[f[x,a],{x,2}]=1/x^2>0 we can Solve D[f[x,a],x]==0 to find the minimize.

D[f[x,a],{x,2}]
(* 1/x^2 *)

Solve[D[f[x, a], x] == 0, x]
(*{{x -> 1/a}}*)

f[x,a]/.%
(* {1 - Log[1/(100 a)]} *)


So the function f[x,a] get it's minimize at x=1/a and the minimize value is

1 - Log[1/(100 a)]

Here I present a direct solution of this "min-min-Problem"

First calculate the minimum depending of a;

min[a_?NumericQ] := {#[], x /. #[]} & [NMinimize[{a*x - Log[x/100], 0.1 < x < 10  }, {x }]]


Second calculate the "worst" a

aworst = a /. NMinimize[{min[a][], 0.1 < a < 1}, a][]
(* 0.1 *)


result

Plot[ {min[a][], min[a][]} , {a, .1, 1},PlotStyle -> {Blue, Red} ,   PlotLabels -> {"min[a]", "x[a]"},GridLines -> {{{aworst, {Thickness[.02],Darker[Green]} }}, None}] • Thanks for the solution. We take the same step but with your implementation works fine! :) Oct 17, 2020 at 14:13