5
$\begingroup$

I could do

vars3d = Array[Through[{x, y, z}@#] &, 5]

to obtain

{{x[1], y[1], z[1]}, {x[2], y[2], z[2]}, {x[3], y[3], z[3]}, {x[4], y[4], z[4]}, {x[5], y[5], z[5]}} 

I'd tried to obtain the following (expected output)

  {{x[6], y[6], z[6]}, {x[9], y[9], z[9]}, {x[10], y[10], z[10]}} 

by doing

vl = {6, 9, 10}
vars3d = Array[Through[{x, y, z}@#] &, vl] # this isn't right.

I would like to know how to obtain the expected output.

$\endgroup$
2
$\begingroup$

If you have to use Array:

Array[Through @ {x, y, z} @ vl[[#]] &, Length @ vl]
 {{x[6], y[6], z[6]}, {x[9], y[9], z[9]}, {x[10], y[10], z[10]}}

Also:

f = Through /@ # /@ #2 &;

f[{x, y, z}, vl]
 {{x[6], y[6], z[6]}, {x[9], y[9], z[9]}, {x[10], y[10], z[10]}}
| improve this answer | |
$\endgroup$
4
$\begingroup$

I can see at least three ways:

Through[{x, y, z}[#]] & /@ vl

Or alternatively:

Transpose[# /@ vl & /@ {x, y, z}]

Or alternatively:

Outer[#2[#1]&, vl, {x, y, z}]
| improve this answer | |
$\endgroup$
3
$\begingroup$
Clear["Global`*"]

vl = {6, 9, 10};

vars3d = Array[Through[{x, y, z}@vl[[#]]] &, 3]

(* {{x[6], y[6], z[6]}, {x[9], y[9], z[9]}, {x[10], y[10], z[10]}} *)

{x[#], y[#], z[#]} & /@ vl

(* {{x[6], y[6], z[6]}, {x[9], y[9], z[9]}, {x[10], y[10], z[10]}} *)

Table[{x[n], y[n], z[n]}, {n, vl}]

(* {{x[6], y[6], z[6]}, {x[9], y[9], z[9]}, {x[10], y[10], z[10]}} *)

% == %% == %%%

(* True *)
| 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.