2
$\begingroup$
β = 100;
v0 = 5*10^-9;

 Reduce[{a/b^2 + 1/a == (2 b)/a^2 + 2/3 β b && (3 v0)/(
      4 π a^2) < b < (3 v0)/(2 π a^2)}, a, Reals] // N

This gives me the output

0.00106077 < b < 0.00133648 && 
 a == Root[-6 b^3 + 3 b^2 #1 - 200 b^3 #1^2 + 3 #1^3 &, 1]

I would like to put the minimum and miximum values of b into bmin and bmax and set a function a(b) i.e.

bmin=0.00106077 
bmax=0.00133648 
a[b_]:=Root[-6 b^3 + 3 b^2 #1 - 200 b^3 #1^2 + 3 #1^3 &, 1]

The thing is I don't want to copy and paste like this because next, I want to be using manipulate to change the values of beta and v0 and I want bmin, bmax, a[b_] to change accordingly.

$\endgroup$
2
  • 1
    $\begingroup$ It won't be hard to do if the output is always in the form b1 < b < b2 && a == a0. Do you know it will always be that way? Or might there be cases where b may lie in multiple intervals or a have multiple values? $\endgroup$
    – Michael E2
    Commented Jan 8, 2017 at 17:13
  • $\begingroup$ Yes as far as I tried using Manipulate to set the range of beta and v they were all in that form $\endgroup$
    – Jun
    Commented Jan 8, 2017 at 17:30

2 Answers 2

4
$\begingroup$

You might approach the problem something like this.

There exists a function ToRules that converts some Reduce output but it doesn't know what to do with inequalities. Disregarding open vs closed intervals we can create a replacement rule to transform these inequalities into Interval expressions:

ineqToIntv = HoldPattern[
  Inequality[m_, Less | LessEqual, s_Symbol, Less | LessEqual, M_] | 
  Inequality[M_, Greater | GreaterEqual, s_Symbol, Greater | GreaterEqual, m_]] :>
    (s == Interval[{m, M}]);

Now:

β = 100;
v0 = 5*10^-9;

sol = Reduce[{a/b^2 + 1/a == (2 b)/a^2 + 2/3 β b && (3 v0)/(4 π a^2) < 
      b < (3 v0)/(2 π a^2)}, a, Reals] // N;

rules = sol /. ineqToIntv // ToRules
{b -> Interval[{0.00106077, 0.00133648}], 
 a -> Root[-6 b^3 + 3 b^2 #1 - 200 b^3 #1^2 + 3 #1^3 &, 1]}

I recommend against defining a since it can conflict with the lines above, so I shall use afn instead:

afn[b_] = a /. rules
{bmin, bmax} = First[b /. rules];

afn[bmin]
afn[bmax]
0.00106079

0.00133652

In this case Interval might be seen as an inconvenience as it simply gets stripped with First, but in other cases it may be useful as arithmetic will operate over the expression, e.g.

b^-1 /. rules
Interval[{748.235, 942.71}]
$\endgroup$
1
  • $\begingroup$ What is Inequality[]? This answer is from 2017 so it is not a recent addition, but I don't find it in MMA 11. (And thanks, I used the idea to do similarly for single sided inequalities) What can one do if one needs pure ">" and open intervals though? $\endgroup$ Commented Oct 28, 2022 at 11:51
2
$\begingroup$

This will get the desired expressions:

β = 100;
v0 = 5*10^-9;

red = Reduce[{a/b^2 + 1/a == (2 b)/a^2 + 
       2/3 β b && (3 v0)/(4 π a^2) < b < (3 v0)/(2 π a^2)}, a, Reals];

N[red] /. {HoldPattern[And[_[b1_, ___, b2_], a == a0_]] :> {a0, {b1, b2}}}
(*  {Root[-6 b^3 + 3 b^2 #1 - 200 b^3 #1^2 + 3 #1^3 &, 1], {0.00106077, 0.00133648}}  *)

As for defining the function a, I would rather not have a be both a variable and a function. To evaluate a at b == b0, use a /. b -> b0. Or define

a[b0_] := a /. b -> b0
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.