Solve equations with condition on variable to reduce the number of solutions

I'm trying to solve an equation, and while it work, "plain" Solve returns two solutions that are, in the specific case, of no interest.

Clear[r, h, V]
V[r_, h_] := \[Pi] r^2 h
A[r_, h_] := \[Pi] r^2 + 2 \[Pi] r h
h0 = h /. Solve[V[r, h] == V0, h][]
D[A[r, h0], r]
Solve[D[A[r, h0], r] == 0, r]

So I tried, as suggested on some web pages,

Solve[D[A[r, h0], r] == 0 && r > 0, r]

but Mathematica returns {}.

What is the correct syntax to get the correct solution? TIA.

(N.B.: Though probably not important for the question, the mathematical problem above is about how to find the radius $$r$$ and height $$h$$ for a circular cylinder with a bottom (no top) that consumes the least material given a volume $$V_0$$.)

Add the information that v0 > 0:

Solve[D[A[r, h0], r] == 0 && r > 0 && V0 > 0, r][]

{r -> ConditionalExpression[Root[-V0 + π #1^3 &, 1], V0 > 0]}

Or specify the domain as PositiveReals:

Solve[D[A[r, h0], r] == 0, r, PositiveReals][]

{r -> ConditionalExpression[Root[-V0 + π #1^3 &, 1], V0 > 0]}

FullSimplify[%, V0 > 0]

{r -> V0^(1/3)/π^(1/3)}

• Thanks! To get the $r$ assigned to a variable $r_0$ I wrote r0 = r /. FullSimplify[%, V0 > 0][]. Is there some 'shorter' syntax to 'extract' the only value when the (double) output list is one item only so I don't have to type []? Trying to understand the FullSimply; why do I have to specify V0>0 again since it was given in the Solve command and also in the ConditionalExpression command?
– mf67
Aug 4 '19 at 21:57
• @mf67, in don't know of any way to avoid using [] (you can put after Solve or after FullSimplify). ConditionalExpresssion does not eliminate the condition V0>0; so wee need to use FullSimplify using the same condition again.
– kglr
Aug 4 '19 at 22:40

From a mathematical point of view this type of problem is sometimes more easily solved using Lagrange multipliers for the constraints,

V[r_, h_] := \[Pi] r^2 h
A[r_, h_] := \[Pi] r^2 + 2 \[Pi] r h + \[Lambda] (V[r, h] - V0)

solns = Solve[{D[A[r, h], r] == 0, D[A[r, h], h] == 0, D[A[r, h], \[Lambda]] == 0}, {r, h, \[Lambda]}]

soln = Map[Reduce[Join[#, {r > 0, h > 0, V0 > 0}]] &, solns /. Rule -> Equal]

Cases[soln, Except[False]]

(* {V0 > 0 && \[Lambda] == (-2*Pi^(1/3))/V0^(1/3) && r == V0^(1/3)/Pi^(1/3) && h == V0^(1/3)/Pi^(1/3)} *)
• That is interesting. The 4th line is however, for me, difficult to understand and I have not (yet) found a good tutorial for all these 'cryptic' commands that are very powerful, once you know them.
– mf67
Aug 4 '19 at 23:28
• To understand line 4, just pull it apart the same way it got put together: Evaluate solns /. Rule -> Equal, see what it does. Take out the Reduce[], evaluate and see what that does. If you don't know Map, see what Map[f, solns/.Rule->Equal] does. Finally, look up the documentation for Function (which will explain # and &). Aug 5 '19 at 0:01