There is a formula to test whether a number is included in a range? For example, if 3 is between -2 and 6.
$\begingroup$ $\endgroup$
4 - $\begingroup$ Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the help center! 3) When you see good questions and answers, vote them up by clicking the vote triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$user9660– user96602015-11-12 09:34:54 +00:00Commented Nov 12, 2015 at 9:34
- $\begingroup$ The key here is to understand what we mean by the range. Do you include all Real numbers between the range ? Only integers ? A start would be to have the list as a Range and use MemberQ $\endgroup$Lotus– Lotus2015-11-12 09:39:17 +00:00Commented Nov 12, 2015 at 9:39
- $\begingroup$ There are things to do after your question is answered. Its a good idea to stay vigilant for some time, better approaches may come later improving over previous replies. Experienced users may point alternatives, caveats or limitations. New users should test answers before voting and wait 24 hours before accepting the best one. Participation is essential for the site, please come back to do your part tomorrow. $\endgroup$rhermans– rhermans2015-11-12 09:51:58 +00:00Commented Nov 12, 2015 at 9:51
- $\begingroup$ As you receive give back, vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. Why not choosing a meaningful username? $\endgroup$rhermans– rhermans2015-11-12 09:53:05 +00:00Commented Nov 12, 2015 at 9:53
Add a comment |
4 Answers
$\begingroup$
$\endgroup$
1 Mathematica 10.3
In Mathematica 10.3 there is a new function Between:
Between[3, {2, 5}] True

Previous versions of Mathematica
You can define your own function with the same behavior:
My take
mybetween[a_, {b_, c_}] := TrueQ[b <= a <= c] or as suggested by @mmal
mybetween[a_, {b_, c_}] := IntervalMemberQ[Interval[{b, c}], a] We can test it:
mybetween[6, {2, 5}] False
mybetween[3, {-2, 6}] True
- 2$\begingroup$ Change
<to≤inmyBetweento get the same behavior as the new built-in function. $\endgroup$shrx– shrx2015-11-12 09:50:27 +00:00Commented Nov 12, 2015 at 9:50
$\begingroup$ $\endgroup$
2 Have a look Range and MemberQ. As well Testing Expressions.
myList = Range[-2, 6, 1] {-2, -1, 0, 1, 2, 3, 4, 5, 6}
myVal = 3 3
MemberQ[myList, myVal] True
- $\begingroup$ Only works for integers though... $\endgroup$sebhofer– sebhofer2015-11-12 12:58:52 +00:00Commented Nov 12, 2015 at 12:58
- $\begingroup$ could be what he meant though.. $\endgroup$george2079– george20792015-11-12 19:02:42 +00:00Commented Nov 12, 2015 at 19:02
$\begingroup$ $\endgroup$
