Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This is kind of a continuation of this question.

I want to automate these 2 steps on Mathematica once I give an integer $N$.

  • generate a list of variables $\{a_i\}_{i=1}^{i=N}$
  • then for some function like $f(x) = e^{x}$ or $f(x) = \sin^2(x)$ compute an expression like $\prod\limits_{i \neq j} f(a_i - a_j)$ or $\sum\limits_{i < j} f(a_i - a_j)$ or $\prod\limits_ {i,j} f(a_i - a_j)$

( - and then hopefully integrate such expressions over all $a_i$...)

I am having to type these expressions by hand for every $N$ and that is very hard once $N$ gets large (one would typically have $\binom{N}{2}$ terms to type by hand!) I would like to know how this can be automated - since I would typically need to to use large $N$.

(...also, help with that previous question would be great!)

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

Implementing for example $\prod_{j>i}^Nf(a_i-a_j)$:

nup = 4;
Times @@ Flatten@Table[f[a[i] - a[j]], {i, 1, nup - 1}, {j, i + 1, nup}]

where nup is $N$.

share|improve this answer
    
...or With[{nup = 6}, Times @@ f /@ Subtract @@@ Subsets[Array[a, nup], {2}]] –  J. M. Oct 16 '12 at 18:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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