| Author |
Comment/Response |
yehuda
|
02/11/13 08:41am
I'll repeat
writing Sum[ f[a] , {a[[1]],0,n} , {a[[2]],0,n} , .... , {a[[N]],0,n} ]
Means
1. you generate a "vector of variables"
2. you define a function f accepting this "vector of variables" as an argument
3. you extract each entry of this "vector of variables" using the index [[1]], [[2]] etc (square brackets for Part[])
4. You define all the a[[i]] iterators
You may avoid ALL of this (besides 2 above) by automation
Using Array + Sequence + Evaluate
Sum[f[Array[z, 5]], Evaluate[Sequence @@ Array[{z[#], 0, 2} &, 5]]]
Replace Array with Table (more typing)
Sum[f[Table[z[i], {i, 5}]],
Evaluate[Sequence @@ Table[{z[i], 0, 2}, {i, 5}]]]
if you want to be more "didactic"
vec = Array[z, 5]
vecIterators = {#, 0, 3} & /@ vec
Sum[f[vec], Evaluate[Sequence @@ vecIterators]]
(*All are the same idea, actually *)
yehuda
URL: , |
|