I have a function and $x$-values as a list. How do I construct a list with coordinates $(x_i,y(x_i))$, $i=1, 2, …$
y[x_]:= 2x
x = { -3, 0, 4, 5}
which should be made into
{ {-3,-6}, {0,0}, {4,8}, {5,10} }
Is there some compact command for this? The following works but is perhaps not optimal;
Table[{x[[i]], y[x][[i]]}, {i, 1, Length[x]}]
Table[{x, y[x]}, {x, xvalues}]
wherexvalues = {-3, 0, 4, 5}
. This is probably the most semantically appealing option. Another solution isTranspose[{x, y /@ x}]
wherex
is as you defined it. Those are general solutions, in your case you have a listable function, which means that you can also use the slightly simplerTranspose[{x, y[x]}]
, and if performance matters then this is what you should use. $\endgroup$Table
variant is the most semantically appealing option but the others worked equally well. $\endgroup$