1
$\begingroup$

Suppose I have a function f which is depending on a,b,c (f[a_,b_,c_]). these a, b, c can take two value zero and infinity. How to have a combination of the function f when it takes zero and infinity values. how many such combinations are possible? Is there any built-in function to carry out this in Mathematica. Actually, the number of variables will increase so I am looking for any built of function exist to carry out this.

$\endgroup$

closed as off-topic by Daniel Lichtblau, Henrik Schumacher, m_goldberg, Sumit, b.gates.you.know.what Nov 23 '18 at 14:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Daniel Lichtblau, Henrik Schumacher, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ Have a look at Tuples. $\endgroup$ – b.gates.you.know.what Nov 20 '18 at 15:19
  • 1
    $\begingroup$ Since there are two choices for each of three parameters, there are 2^3 possible parameter settings. More generally, for n choices with m parameters, there are n^m possible parameter settings. $\endgroup$ – Bob Hanlon Nov 20 '18 at 15:38
  • $\begingroup$ yes, you are correct. but my question was is there any built-in function in Mathematica for doing this. $\endgroup$ – acoustics Nov 20 '18 at 17:06
3
$\begingroup$

Tuples gives you the combination of elements, in your case Tuples[{0, ∞}, 3].

{{0, 0, 0}, {0, 0, ∞}, {0, ∞, 0}, {0, ∞, ∞}, {∞, 0, 0}, {∞, 0, ∞}, {∞, ∞, 0}, {∞, ∞, ∞}}

Since that returns a matrix, you can evaluate your function if you put the variables in brackets and use Map. A tractable example where instead of inf I use 1.

f[{a_, b_, c_}] := a + b + c
f /@ Tuples[{0, 1}, 3]

{0, 1, 1, 2, 1, 2, 2, 3}

$\endgroup$
  • $\begingroup$ It solves my problem thanks. Tuples function is very helpful while handling combinations. $\endgroup$ – acoustics Nov 20 '18 at 17:14
  • 1
    $\begingroup$ Or with the original form for f use Apply: f[a_, b_, c_] := a + b + c; f @@@ Tuples[{0, 1}, 3] $\endgroup$ – Bob Hanlon Nov 20 '18 at 18:40

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