1
$\begingroup$

Can you help me on the following question?

Generate the list

{{0}, {0, 2}, {0, 2, 4}, {0, 2, 4, 6}, {0, 2, 4, 6, 8}}  

using the Table function.

Here is a simple way to generate it:

A = {0, 2, 4, 6, 8}
list1 = 
  {{A[[1]]}, 
   {A[[1]], A[[2]]}, 
   {A[[1]], A[[2]], A[[3]]}, 
   {A[[1]], A[[2]], A[[3]], A[[4]]}, 
   {A[[1]], A[[2]], A[[3]], A[[4]], A[[5]]}}

but what does it mean by using the Table function ???

$\endgroup$
  • $\begingroup$ I guess, the point is to automate the process so that one can also generate {{0},{0,2},{0,2,4},{0,2,4,6},{0,2,4,6,8}, ..., {0,2,4,..., 1000}}. Table allows you to do that if you identify the pattern of the sequence. $\endgroup$ – Henrik Schumacher Oct 29 at 13:17
  • $\begingroup$ Try: i = 0; NestList[Append[#, ++i 2] &, {0}, 5] $\endgroup$ – Daniel Huber Oct 29 at 13:22
  • $\begingroup$ Table lets you automatically generate lists as some parameter (or parameters) range over some values. So for example, Table[n^2, {n, 2, 6}] gives you a list of the values n^2 for n starting at 2 and going up to 6, i.e. {4,9,16,25,36}. You can also iniclude a step size, so that it increases the value of n in steps of that size, as Table[n^2, {n, 2, 11, 3}] for example, which gives n^2 for n starting at 2 and increasing in steps of size 3 until it hits 11, so that n equals 2, 5, 8, 11. $\endgroup$ – thorimur Oct 29 at 13:29
  • $\begingroup$ You can also use multiple parameters, which will create nested tables, as in Table[n^k, {n,1,5},{k,0,3}], which will create {{1, 1, 1, 1}, {1, 2, 4, 8}, {1, 3, 9, 27}, {1, 4, 16, 64}, {1, 5, 25, 125}}`. The order in which you provide the parameters determines which list is "inside"—try switching them and see what you get! $\endgroup$ – thorimur Oct 29 at 13:32
  • $\begingroup$ Also note that you can browse the documentation here: reference.wolfram.com/language . For Table in particular, check out reference.wolfram.com/language/ref/Table.html?q=Table . Your Mathematica copy should also provide a "help" button in the top right of each window, and clicking on that will bring you to this documentation (but inside of mathematica, so that you can actually play with it as a notebook!) $\endgroup$ – thorimur Oct 29 at 13:32
1
$\begingroup$

You are probably expected to use Table like this:

A = {0, 2, 4, 6, 8};
Table[A[[;; i]], {i, Length[A]}]
{{0}, {0, 2}, {0, 2, 4}, {0, 2, 4, 6}, {0, 2, 4, 6, 8}}

Or in some equivalent way such as:

 Table[i, {k, A}, {i, 0, k, 2}]
| improve this answer | |
$\endgroup$
0
$\begingroup$
Table[2 Table[i, {i, 0, k}], {k, 0, 4}]

(* {{0}, {0, 2}, {0, 2, 4}, {0, 2, 4, 6}, {0, 2, 4, 6, 8}} *)
| improve this answer | |
$\endgroup$

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