2
$\begingroup$

I would like to build a function that returns true if there exists even one value of xg1 such that having as inputs Mtot, PL, xg2, mac, xga, and defining

xgtot = (xg1 PL + xg2 Mtot)/(Mtot + PL);
stab = (xga - xgtot)/mac;

the following conditions are satisfied:

0.1<stab<0.4
xgtot<0.2;

I would like such a function to return only True or False.

I tried using AnyTrue, but it doesn't seam to work as I wanted:

    tests = {0.1<#1 < 0.4 &, #2 < 0.2 &};
AnyTrue[{stab, xg1} , TrueQ[tests] ]

Any suggestions?

$\endgroup$
4
  • 1
    $\begingroup$ Perhaps you could write a function that uses FindInstance or Reduce, then if an answer is returned by those functions, it in turn returns True, otherwise False. $\endgroup$
    – MarcoB
    Commented May 18, 2016 at 12:29
  • $\begingroup$ It seams to work out with FindInstance. How may I make it return True or False? $\endgroup$ Commented May 18, 2016 at 12:42
  • 2
    $\begingroup$ To make it return True or False, just test whether its output is {} (False) or something else (True). The following would work: FindInstance[(*tests*), {(*variables*)}] =!= {} You may also want to know that =!= is a short for UnsameQ. $\endgroup$
    – QuantumDot
    Commented May 18, 2016 at 12:54
  • 1
    $\begingroup$ And if you reply to a comment, you should add a @MarcoB somewhere in your comment to send him a 'notification'. Otherwise he won't know you replied. $\endgroup$
    – QuantumDot
    Commented May 18, 2016 at 12:59

2 Answers 2

6
$\begingroup$

Mainly just to see how Reduce@Exists[..] stacks up against FindInstance[]. I suspect the heuristics of FindInstance will often beat symbolic reduction, but apparently not in this case.

Clear[xg1, Mtot, PL, xg2, mac, xga, stab, xgtot];
xgtot = -(xg1 PL + xg2 Mtot)/(Mtot + PL);
stab = (xga - xgtot)/mac;
Reduce[
  Exists[{xg1, Mtot, PL, xg2, mac, xga}, 
   0.1 < stab < 0.4 && xgtot < 0.2]
  ] // RepeatedTiming
FindInstance[0.1 < stab < 0.4 && xgtot < 0.2,
   {xg1, Mtot, PL, xg2, mac, xga}] =!= {} // RepeatedTiming
(*
  {0.0081, True}
  {0.0087, True}
*)
$\endgroup$
2
$\begingroup$

Following MarcoB's comments and QuantumDot's suggestion, a solution could be to simply use FindInstance:

    FindInstance[(xga - (xg1 PL + xg2 Mtot)/(Mtot + PL))/mac < 0.4 && 
   xg1 > 0.3 && 0.1 < stab < 0.4, {xg1}] =!= {}

Thank you very much!

$\endgroup$

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.