1
$\begingroup$

Potentially very silly question here.

What I have:

xaxis = {r, 0, 3}

And if I do:

Plot[r^2, xaxis]

it works.

I'd like to the same for a Table, i.e. defining its paratemers (range, step etc.) elsewhere and then just importing them, like so:

Table[r, Append[xaxis, 0.1]]

where the 0.1 there is the step I am taking.

This does not work however!
Is it not possible at all?
Do I have to define it like Table[r, {r,0,3,0.1}] ?

$\endgroup$
  • 1
    $\begingroup$ Table[r, Evaluate@Append[xaxis, 0.1]] $\endgroup$ – Bob Hanlon Jan 29 '18 at 16:48
  • $\begingroup$ That solved it, thanks. Any physical reason as to why this works and method did not? $\endgroup$ – SuperCiocia Jan 29 '18 at 16:54
  • $\begingroup$ Table has the attribute HoldAll $\endgroup$ – Bob Hanlon Jan 29 '18 at 16:56
  • $\begingroup$ Thanks. Out of curiosity how do I know this? I couldn't find it mentioned on the documentation? $\endgroup$ – SuperCiocia Jan 29 '18 at 17:05
  • 2
    $\begingroup$ Evaluate ?? Table $\endgroup$ – Bob Hanlon Jan 29 '18 at 17:06
1
$\begingroup$

I would try to work with the syntax:

Table[body, {iter, values}]

instead. Then, you could use:

xaxis = Sequence[0, 3];
xiter = Range[xaxis];

(* Table *)

Table[x, {x, xiter}]
(* or *)
Table[x, {x, Range[xaxis]}]

(* Plot *)  
Plot[x, {x, xaxis}]

{0, 1, 2, 3}

{0, 1, 2, 3}

enter image description here

Your step version would be:

xiter = Range[xaxis, .1];

Table[x, {x, xiter}]
(* or *)    
Table[x, {x, Range[xaxis, .1]}]

{0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1., 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2., 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.}

{0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1., 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2., 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.}

| improve this answer | |
$\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.