3
$\begingroup$

I would like to modify the question a bit. I want to plot the function m with different combination of (a1,b1,a2,b2) over a range of d generated also by Reduce below. How can I do that? I don't want to manually input all combination.

intvars ={a1,b1,a2,b2};
m = (a2 (-1+d)-a1 d) /(b2+b1 d-b2 d);
vd =a1 + b1 m;
vdb = a2 + b2 m;
assumptions=And@@Thread[-2<= intvars <= 2] && Element[intvars,Integers] &&
 Element[d,Reals] && vd >0 && vdb<0;
comb=Reduce[assumptions];
Plot[m, (each of combination of (a1, b1,a2, b2) from comb and d range from comb]
$\endgroup$
  • 2
    $\begingroup$ Manipulate with (a1,b1,a2,b2) as parameters? $\endgroup$ – Alx Jan 21 at 5:14
  • $\begingroup$ That's good. I didn't know it's possible with many parameters like that. One problem though. I would like to plot and see the range of the function with each combination. Because there are two many combinations 5^4 which is 625, so I can't do manually check all combination. I forgot what I have checked. Is there a better way to solve this? $\endgroup$ – anhnha Jan 21 at 5:24
4
$\begingroup$

The following seems to work:

intvars = {a1, b1, a2, b2};
m = (a2 (-1 + d) - a1 d)/(b2 + b1 d - b2 d);
vd = a1 + b1 m;
vdb = a2 + b2 m;
assumptions = 
  And @@ Thread[-2 <= intvars <= 2] && Element[intvars, Integers] && 
   Element[d, Reals] && vd > 0 && vdb < 0;
comb = Reduce[assumptions];
Plot[
 comb //
   BooleanConvert //(* convert to normal form *)
   Apply@List //(* convert sol1 || sol2 || … to {sol1, …} *)
   Map@Apply@List (*  convert each cond1 && cond 2 && … to {cond1, …} *)//
   Map[(* for each list of conditions… *)
    ConditionalExpression[(* build a ConditionalExpression *)
      m /. ToRules[And @@ Cases[#, _Equal]] (* use equalities to replace params *),
      And @@ Cases[#, Except@_Equal](* extract the inequalities *)
      ] &
    ] //
  Evaluate,
 {d, 0, 1}
 ]

enter image description here

The key idea is to use BooleanConvert to bring the solution of Reduce into the form sol1 || sol2 || …, where each of the sol is again eq1 && eq2 && …. Then we simply extract the equalities and convert them to replacement rules with ToRules. The remaining inequalities are used as conditions in ConditionalExpression.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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