# 3D Plot the result of local Minimize with varying parameter values

I'm faced with the following minimization problem: Find $$r\in[0,1]$$ that minimizes $$\frac{d^2+k^2 (1-2r)r}{2(1-r)r}$$, which is bounded by 0 and 1. In addition, $$k holds and each of $$d$$ and $$k$$ is bounded by zero and some positive real number, say, $$d\in[0,2]$$ and $$k\in[0,0.5]$$.

I'm in need of help to 3D plot the value of $$r$$ against $$d$$ and $$k$$.

Here is what I tried:

Plot3D[NMinimize[{-((d^2 + k^2 (1 - 2 r) r)/(2 (-1 + r) r)), 0 <= d <= 2, 0 <= k <= 0.5, 0 <= r <= 1}, r], {d, 0, 2}, {k, 0, 0.5}]


If I have understood your question correctly, you search for an "r" in the range [0,1], which makes the object function minimal, under the constraints d->[0,2] and k->[0,1/2].

minR = Last @ Minimize[{(d^2 + k^2 (1 - 2 r) r)/(2 (1 - r) r), 0 < r < 1, 0 < d < 2, 0 < k < 1/2}, r] Plot3D[r /. minR, {d, 0, 2}, {k, 0, 1/2}, PlotRange -> All, AxesLabel -> Automatic] Furthermore, you get the function value:

value = First @ Minimize[{(d^2 + k^2 (1 - 2 r) r)/(2 (1 - r) r), 0 < r < 1,  0 < d < 2, 0 < k < 1/2}, r] This value should be minimal and bounded -> [0,1]. That's true for d = k and the object function is reduced to minObjFunc and r = 1:

minObjFunc = 1/2 (2 d^2 + k^2) /. d -> k
(3 k^2)/2

r /. (minR // PiecewiseExpand)[] /. d -> k
1

• I have to express myself precisely: "Under these conditions, the value of the objective function becomes "minObjFunc ", (first row of the piecewise result) – rmw Feb 17 '19 at 18:42

Although the observation by bill_s is correct, progress can nonetheless be made:

s = MinValue[{(d^2 + k^2 (1 - 2 r) r)/(2 (1 - r) r), 0 < r < 1}, r]
(* Piecewise[{{d^2 + Sqrt[d^4], (k == 0 && d > 0) || (k == 0 && d < 0)},
{(2*d^2 + k^2 - 2*Sqrt[d^2*(d^2 - k^2)])/2, (k > 0 && d == -k) || (k > 0 && d == k) ||
(k < 0 && d == -k) || (k < 0 && d == k)}, {(2*d^2 + k^2 + 2*Sqrt[d^2*(d^2 - k^2)])/2,
(k > 0 && d > k) || (k > 0 && d < -k) || (k < 0 && d > -k) || (k < 0 && d < k)},
{-Infinity, (k > 0 && Inequality[-k, Less, d, Less, k]) ||
(k < 0 && Inequality[k, Less, d, Less, -k])}}, 0] *)

Plot3D[s, {d, 0, 2}, {k, 0, .5}, ImageSize -> Large,
AxesLabel -> {d, k, min}, LabelStyle -> {Black, Bold, 15}] The solution is negative infinity for k < d and is shown by the plot otherwise.

• Thanks! I forgot to add the condition k<d, which I just did in my post. I think I'm not perfectly understanding your work here. I'm sorry but can you please give a little more explanation on what's going on? And I would like to plot with r on the vertical axis. – ppp Feb 17 '19 at 5:53
• Another edit: my objective function is bounded by 0 and 1. – ppp Feb 17 '19 at 6:02
• @bbgodfrey Please insert the result as an image, it is then clearer to recognize. I get the same result. – rmw Feb 17 '19 at 10:17
• @ppp It appears that rmw adequately answered your question. – bbgodfrey Feb 17 '19 at 16:59

If you let d=0 and k=0.2, then the minimization is unbounded:

d = 0; k = 0.2;
NMinimize[{-((d^2 + k^2 (1 - 2 r) r)/(2 (-1 + r) r)),
0 <= d <= 2, 0 <= k <= 0.5, 0 <= r <= 1}, r]

{-\[Infinity], {r -> Indeterminate}}


Since that is right in the middle of the range you are looking at, there is nothing to plot.

• Thanks! I have made two edits. In fact, my object function should be bound by 0 and 1. In addition, k<d should hold. Under these additional constraints, do we get more meaningful results? Any comments will be greatly appreciated. – ppp Feb 17 '19 at 5:59