6

2

I want to use concise code to generate a table of values that list the addition of a set of vectors. What I am looking for is essentially a Table of Tables.

I will show here the kind of lists I want, which I am able to generate individually.

First, let's define a set of say 6 vectors (an ordered pair):

```
H = Table[{Cos[n*Pi/3], Sin[n*Pi/3]}, {n, 0, 5, 1}];
```

This will be our first Table. Next, I want to get all vectors that result from adding any two vectors in H together:

```
H2 = Table[H[[i1]] + H[[i2]], {i1, 1, 6, 1}, {i2, 1, 6, 1}];
```

Now we create another Table, but this time with all vectors that result from choosing three vectors from the set H and adding them together:

```
H3 = Table[H[[i1]] + H[[i2]] + H[[i3]], {i1, 1, 6, 1}, {i2, 1, 6, 1}, {i3, 1, 6, 1}];
```

Suppose we were to continue creating tables like this with arbitrarily many sums of this type. How can I create one single Table that would combine them all?

I am aware that I can use some function like Append to join them all together after each one has been generated, but I am looking for something more efficient that can be done a single cell.

I have something in mind along the following lines (note that this is not properly functioning code, but I am writing it for illustrative purposes). It would be nice to be able to generalize these Tables using something like this, where I've attempted to index the variables (incorrectly?):

```
H[N_] =
Table[
Sum[ H[[i_j]] , {j, 1, N, 1}],
{i_1, 1, 6, 1}, {i_2, 1, 6, 1}, ... {i_N, 1, 6, 1}] ;
```

Then I could create a single table with say 10 iterations using:

```
Table[ H[N],{N,1,10,1}]
```

Unfortunately, I am unable to index variables in this way because Mathematica tells me the variable names are "Protected". How can I get around this?

1@Nasser you don't need

`Function`

:`Total /@ ...`

will do. – Mr.Wizard – 2012-12-25T04:53:49.360@Nasser thanks for the tip! That's a significant difference indeed. Interesting that

`Total/@data`

is noticeably faster than`Apply[Plus,#]&/@data`

, too. Is there a more general key point to take away from this? I'm not sure I understand exactly why there's such a speed difference. – Royce – 2012-12-25T10:46:51.973