1
$\begingroup$

I would like to use Array[] or a similar function that gives out a list of vector-like functions evaluated at different numbers. For a scalar function f this is perfectly doable with Array[]:

f[x_] = x^2;
Array[f,3]

(*
{1,4,9}
*)

If f was not a scalar function and if I wanted to include other vectors as well I would expect something like:

a[x_] = {x,1,1+x^2};
b[x_] = {x,x^2,x^3};

Function[{a[x],b[x]},3]

(*
{{{1,1,2},{2,1,5},{3,1,10}},{{1,1,1},{2,4,8},{3,9,27}}
}
*)

One can see that a[x] was evaluated at x = 1, 2, 3 and then b[x] was appended at values x = 1, 2, 3 as well.

$\endgroup$
2
$\begingroup$

You can use Array in several alternative ways:

Array[#, 3] & /@ {a, b}

Map[Array[#, 3] &] @ {a, b}

Transpose @ Array[Through @ {a, b} @ # &, 3]

Array[Through @ {a, b} @ # &, 3, 1 , Transpose[{##}] &]

all give

{{{1, 1, 2}, {2, 1, 5}, {3, 1, 10}}, {{1, 1, 1}, {2, 4, 8}, {3, 9, 27}}}

Alternatively, you can use Table:

Table[i[j], {i, {a, b}}, {j, 3}]

or

Transpose @ Table[{a[x], b[x]}, {x, 3}]

to get

{{{1, 1, 2}, {2, 1, 5}, {3, 1, 10}}, {{1, 1, 1}, {2, 4, 8}, {3, 9, 27}}}

$\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.