New answers tagged

3

Here is a direct translation of your if expressions using Mathematica's Which: a = 1; b = 2; c = 3; d = 4; Which[ (a < 4 || b > 5) && ((c == 3 || d <= 6) && (c + d < 10)), a = 10; b = 20; c = 30; d = 40, (a <= 2) && (c == 3 || d <= 6), a = 100; b = 200; c = 300; d = 400, True, a = 1000; b = 2000; ...


0

The Mathematica commands If and And should do the trick: If[query, "if true, run this code", "if false, run this code"] Using two If functions should do the trick. The function And should be pretty self-explanatory. As a beginner, putting a question mark (?) before any function will give you a rundown of it.


4

Given: list = {-3., -2.6, -2.2, -1.8, -1.4, -1., -0.6, -0.2, 0.2, 0.6, 1., 1.4, 1.8, 2.2, 2.6, 3.}; {min, max} = {-1.5, 3}; {pos, non} = {50, 700}; I'd just stick with a direct expression of the requirement: Replace[list, x_ /; min < x < max :> If[Positive[x], pos, non], {1}] (* {-3., -2.6, -2.2, -1.8, 700, 700, 700, 700, 50, 50, 50, 50, 50, 50,...


2

You are correct. It is the logical OR function. It evaluates its arguments in order, giving True immediately if any of them are True, and False if they are all False. https://reference.wolfram.com/language/ref/Or.html



Top 50 recent answers are included