# Solving an equation with 3 free parameters in a way that satisfies a condition

I have an equation in terms of $$q$$, $$c_2$$, $$c_3$$ and $$r$$. I just know that $$q$$ and $$r$$ are positive (there are no restrictions on $$c_2$$ and $$c_3$$).

eq1 = (10 q^2)/r^3 - 2 (3 c3 + c2 r)


Solving this equation in terms of r with the mentioned conditions gives:

sol1 = r /. Solve[eq1 == 0 && q > 0 && r > 0, r, Reals]

{ConditionalExpression[
Root[-5 q^2 + 3 c3 #1^3 + c2 #1^4 &, 1],
0 < q < 27/16 Sqrt[3/5] Sqrt[-(c3^4/c2^3)] &&
c2 < 0 && c3 > 0],
ConditionalExpression[
Root[-5 q^2 + 3 c3 #1^3 + c2 #1^4 &, 2],
(c2 > 0 && c3 > 0 && q > 0) ||
(0 < q < 27/16 Sqrt[3/5] Sqrt[-(c3^4/c2^3)] && c2 < 0 && c3 > 0) ||
(c3 < 0 && c2 > 0 && q > 0)]}


I want those solutions of this equation with the two roots which make eq3 positive:

eq3 = (3 c3 + 2 c2 r)/(8 π r^3);


I couldn't find the analytic way to do that, but here is my numeric code to find parameters for which the condition comes true. It takes too long and is not at all efficient — so far I have not found even one set of parameters to satisfy the condition).

ansnum =
Flatten[
ParallelTable[{q, c2, c3, sol1},
{q, 0.001, 1, 0.01}, {c2, -20, 0.001, 0.1}, {c3, 0.001, 20, 0.1}], 2];

ansnum = ansnum /. Undefined -> -100;

j = 0;

Table[
If[ansnum[[i, 4, 1]] != -100 && Length[ansnum[[i, 4]]] == 2,
j = j + 1;
eq3fin[j] =
{ansnum[[i, 1]],
ansnum[[i, 2]],
ansnum[[i, 3]],
{ansnum[[i, 4, 1]], ansnum[[i, 4, 2]]},
{eq3 /.
{q -> ansnum[[i, 1]], c2 ->  ansnum[[i, 2]],
c3 ->  ansnum[[i, 3]], r ->  ansnum[[i, 4, 1]]},
eq3 /.
{q -> ansnum[[i, 1]], c2 ->  ansnum[[i, 2]],
c3 ->  ansnum[[i, 3]], r ->  ansnum[[i, 4, 2]]}}}],
{i, 1, Length[ansnum]}] /. Undefined -> Sequence[];

Table[
If[eq3fin[j][[5, 1]] > 0; eq3fin[j][[5, 2]] > 0,
Print[eq3fin[j]]],
{j, 1, j}];


My question is that is there any analytical way to do this? If no, how can I make my numerical code efficient?

I'm not sure what you're trying to do, but one idea is to include the constraint eq3>0 in your Solve:
sol1 = r /. Solve[eq1 == 0 && q > 0 && r > 0 && eq3 > 0, r, Reals]

Examining the conditions, we see that the first root requires $$c2<0$$ while the second root requires $$c2>0$$. So there are no combinations of the parameters where both roots are solutions.