3
$\begingroup$

I have function for table $t$

t[n_] := Table[i*n, {i, 1, 3}];

For example t[1]=(1, 2, 3), t[2]=(2, 4, 6), and t[3]=(3, 6, 9)

To join $n=3$ tables side by side into $3\times3$ matrix I use

tall = Join[{t[1], t[2], t[3]}];

How to generalize coding for to work for $n=10, 100$ or $1000$ tables? With big number $m$ gives $m \times 3$ matrix.

$\endgroup$
  • 1
    $\begingroup$ t /@ Range[100]? $\endgroup$ – kglr Dec 15 '19 at 5:51
7
$\begingroup$

This

t[1]={1, 2, 3}; t[2]={2, 4, 6}; t[3]={3, 6, 9};t[4]={4,8,12};
tall=Table[t[i],{i,4}]

instantly gives you

{{1,2,3},{2,4,6},{3,6,9},{4,8,12}}

Replace the 4 with 10 or 100 or 1000

$\endgroup$
4
$\begingroup$

To get m tables, you can Map the function t on Range[m]:

m = 7;
t /@ Range[m]

{{1, 2, 3}, {2, 4, 6}, {3, 6, 9}, {4, 8, 12}, {5, 10, 15}, {6, 12, 18}, {7, 14, 21}}

Alternatively, you can use Array:

Array[t, m]

{{1, 2, 3}, {2, 4, 6}, {3, 6, 9}, {4, 8, 12}, {5, 10, 15}, {6, 12, 18}, {7, 14, 21}}

$\endgroup$
3
$\begingroup$

Add a DownValue to t such that it can also take a start n and an end m integer

t[n_] := Table[i*n, {i, 1, 3}];
t[n_, m_:0] := Table[i*(n+j), {j, 0, m-n}, {i, 1, 3}]

E.g.

t[5]

{5,10,15}

t[3,5]

{{3, 6, 9}, {4, 8, 12}, {5, 10, 15}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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