# Minimizing the largest difference between two functions

I have two functions defined on the same domain, f(x)f(x) and g(x)g(x) where xx is in (0,1)(0,1):

f[x_] := (-1 + x) Log[1 – x] – x Log[x]
g[x_] := Log[1 + 2 (-1 + x) x]

I would like to find a constant cc such that the maximum of f(x)−cg(x)f(x)-cg(x) is minimized on the domain (0,1)(0,1).

My first attempt was to try

Minimize[Maximize[{f[x]-c g[x],0 -1.14363}} *)

The sharp corner gives FindMinimum some trouble, as it expects a smooth function (we get a FindMinimum::sdprec message) but we can verify on the graph that the minimum was indeed found correctly.

Thank you very much for your answer. It seems that ?NumericQ is the main ingredient I was missing. There’s a lot of voodoo (for me) with Map/pure functions/Apply etc. which I found searching through related questions but this answer solved my problem perfectly.
Apr 1 ’15 at 14:21

I take it you are interested in the minimum in the absolute value of the difference Abs[f[x]-c g[x]]. Otherwise, the answer is trivial: c=-Infinity.
Let us define the functions:

f[x_] := (-1 + x) Log[1 – x] – x Log[x];
g[x_] := Log[1 + 2 (-1 + x) x];
w[x_, c_] := f[x] – c*g[x];

and plot them:

Manipulate[Plot[w[x, c], {x, 0, 1}], {c, -3, -0.1}]

yielding this:

From playing with it it becomes clear that the minimum value of the function Abs[f[x]-c g[x]] takes place somewhere at negative cbetween about -1.25 and -0.3, where there are three extremes, two of them being different. Or at least it looks like that. I did not check this, but you may make a check analogously to what is written below.
Let us take this interval and determine the absolute maximum:

lst = Table[{c,
Max[Abs[FindMaximum[w[x, c], {x, 0.1}][[1]]],
Abs[FindMinimum[w[x, c], {x, 0.45}][[1]]]]}, {c, -1.251, 0,
0.001}] // Quiet;

ListPlot[lst,
AxesLabel -> {Style[“c”, 16, Italic],
Style[“Max[Abs[w]]”, 16, Italic]}]

returning this:

Now it is not difficult to find the point, where it is absolute minimum:

lst[[Position[lst, Min[Transpose[lst][[2]]]][[1, 1]]]]

(* {-1.142, 0.0985002} *)

This may be at least one way of how practically to get the value.

Have fun!