More complete solution added at the end.
More complete solution.
Having determined that the true minimum is on the boundary, we can look at the boundaries specifically. There are four lines/curves to examine:
Line 1: r=0, k=d to 1
Manipulate[
Manipulate[
Plot[f[k, 0, d, s], {k, d, 1},
PlotLegends -> {"r = 0, f vs. k"}],
{s, 2 d, 10}],
{{d, 0.5}, 0, 1}]
Playing with the sliders will demonstrate to you that the minimum is always at k=1. Therefore Possibility 1 will be defined by {k,r}={1,0}, with a value of:
f[1, 0, d, s]
(* -((1 - 2 d + d^2 - 2 d s)/(2 s^2)) *)
Line 2: k=d, r=0 to 1
Manipulate[
Manipulate[
Plot[f[d, r, d, s], {r, 0, 1},
PlotLegends -> {"k = d, f vs. r"}],
{s, 2 d, 10}],
{{d, 0.5}, 0, 1}]
Playing with the sliders we can see that the minimum is always at r=0, which is the left-most point from line 1. And we already know that the right-most point from line 1 is always lower than the left-most point, so we have no new possibilities for a minimum here.
Line 3: k=1, r=0 to d
Manipulate[
Manipulate[
Plot[f[1, r, d, s], {r, 0, d},
PlotLegends -> {"k = 1, f vs. r"}],
{s, 2 d, 10}],
{{d, 0.5}, 0, 1}]
Playing with the slider here shows that the minimum could be either end of this line, depending on the values of d and s. The left-most point, {k,r}={1,0} is already Possibility 1. The right-most point is given by {k,r}={1,d} and has a value given by:
Simplify[f[1, d, d, s]]
(* (-1 + 4 d)/(2 s^2) *)
We will call this Possibility 2.
Line 4: k=d to 1, while r=d/k at each point.
Manipulate[
Manipulate[
Plot[f[k, d/k, d, s], {k, d, 1},
PlotLegends -> {"k = 1, r=d/k, f vs. k"}],
{s, 2 d, 10}],
{{d, 0.5}, 0, 1}]
Again we find that the minimum along this line could be either end. The right-most possibility is Possibility 2, which we discussed above. The left-most point is a singularity, but we can take the limit, which we will call Possibility 3:
f[d, 1, d, s]
(* ComplexInfinity *)
Limit[f[k, d/k, d, s], k -> d]
(* (3 d^2)/(2 s^2) *)
Summary
So there are three possible solutions:
- {k,r} = {1,0}, f = -((1 - 2 d + d^2 - 2 d s)/(2 s^2))
- {k,r} = {1,d}, f = (-1 + 4 d)/(2 s^2)
- {k,r} = {d,1}, f = (3 d^2)/(2 s^2)
So when is each solution correct? Well, let's see:
one[d_,s_]=-((1 - 2 d + d^2 - 2 d s)/(2 s^2));
two[d_,s_]=(-1 + 4 d)/(2 s^2);
three[d_,s_]=(3 d^2)/(2 s^2);
The conditions under which the first solution is the true minimum are:
Reduce[{one[d, s] < two[d, s], one[d, s] < three[d, s], 0 <= d <= 1,
2 d < s}, {d, s}]
(* (0 < d <= 1/3 && 2 d < s < (2 + d)/2) || (1/3 < d < 1/2 &&
2 d < s < (1 - 2 d + 4 d^2)/(2 d)) *)
The conditions under which the second solution is the true minimum are:
Reduce[{one[d, s] > two[d, s], two[d, s] < three[d, s], 0 <= d <= 1,
2 d < s}, {d, s}]
(* 0 < d < 1/3 && s > (2 + d)/2 *)
And the conditions under which the third solution is the true minimum are:
Reduce[{one[d, s] > three[d, s], two[d, s] > three[d, s], 0 <= d <= 1,
2 d < s}, {d, s}]
(* (1/3 < d <= 1/2 && s > (1 - 2 d + 4 d^2)/(2 d)) ||
(1/2 < d < 1 && s > 2 d) *)
There's a moral here. As magnificent a package as Mathematica is, there is no substitute for breaking the problem down and thinking about it.