0
$\begingroup$

How do I write 0 < x < 10 on the right side in the equation. If #1 + #2 is bigger than 0 and smaller than 10. And is it possible to require -10 < x < 10 with the additional condition x != 0

If[#1 + #2 == ??, ... ]
$\endgroup$
  • 2
    $\begingroup$ It's not really clear what you want here. If you're testing the summed slots then you can just say 0<#1+#2<10 and it'll return True/False if the sum is in/out of that range. $\endgroup$ – IPoiler Dec 1 '15 at 18:46
  • $\begingroup$ The syntax for Less[ ] is Less[1, 2, 3, ...] or the shorthand 1 < 2 < 3 Try them out $\endgroup$ – Dr. belisarius Dec 1 '15 at 18:50
  • $\begingroup$ I am using this If[Last[#3 - #2] == 0 && First[#2 - #1] == 1, "01 X" <> ToString@First@#2 <> " Y" <> ToString@Last@#2, Unevaluated@ Sequence[ "00 X" <> ToString@First@#2 <> " Y" <> ToString@Last@#2, "01 X" <> ToString@First@#2 <> " Y" <> ToString@Last@#2] ] & and would like to get 0 < X <10 instead of 0 but i can't seem to make it work. EDIT: just saw your last comment, going to try it. $\endgroup$ – EminemIsLife Dec 1 '15 at 18:51
  • $\begingroup$ I have tried the following and something similar: Example: list = {{1, 2}, {1, 2}} Last[#1 + #2] == [Less[5] && Greater[3]] & , not sure if I should use == at all, i dont know what to do. $\endgroup$ – EminemIsLife Dec 1 '15 at 19:06
  • $\begingroup$ try to add a clear explanation of what you are actually trying to accomplish (edit the question, not in comment) $\endgroup$ – george2079 Dec 1 '15 at 19:28
2
$\begingroup$

You can put more conditions in with the "and" operator "&&", e.g.:

Plot[If[x < 1 && x > 0, 2, -2], {x, -2, 2}]

enter image description here

And you second example would be

If[{-10 < x < 10 && x != 0}, 1, 2]
$\endgroup$
1
$\begingroup$

You can work with ConditionalExpression or Condition or Piecewise

f[x_] := x^2 /; 0 < x < 10
Plot[f[x], {x, -10, 10}]

enter image description here

h[x_] := 3 x/Sin[x] /; -10 < x < 10 && x != 0
Plot[h[x], {x, -20, 20}]

enter image description here

g[x_] := Piecewise[{{-x^2, 0 < x < 10}, {2 x, -10 < x < 10 && x != 0}}]
Plot[g[x], {x, -20, 20}, Frame -> True]

enter image description here

And with Assumptions

FunctionExpand[x^2/Sin[x], Assumptions -> 0 < x < 10]

x^2 Csc[x]

Plot[x^2 Csc[x], {x, -37.6991, 37.6991}]

enter image description here

$\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.