Hi,
I have 2 functions f[x] and g[x] defined.
I would like to compare them by displaying some values.
So I build two tables :
tbA = Table[f[x],{x,1,4}]
tbB = Table[g[x],{x,1,4}]
Can I define the “iterations” i.e. {x,1,4} before defining the tables, so as I have not to duplicate them?
Thanks for help.
Hi Francois
Since Table has the HoldAll attribute this does not work
xRange = {x, 1, 4};
Table[x, xRange]
(* Non-list iterator xRange at position 2 does not evaluate to a real numeric value *)
Have to force evaluation
Table[x, Evaluate@xRange]
(* {1, 2, 3, 4} *)
To keep the range separate from the iteration symbol
range = {1, 4};
Table[x, Evaluate@{x, Splice@range}]
(* {1, 2, 3, 4} *)
If you need to compare the values, you may try this:
Table[{f[x], g[x]}, {x, 1, 4}] // TableForm
mikebesso
(Mike Besso)
5
@Rohit Namjoshi , @Gianluca Gorni :
I’ve been struggling with this as well. Now I understand why I was struggling, and I have two new techniques to use.