# Generating a Table with two fixed variable and varying the third variable

I want to generate a table in which two of the variables (x,y) are fixed with 1<->1 correspondence while the third variable is varying in the given range for each each sublist. I want to program for this in the input, NOT by generating the general output and then removing the unnecessary part. Example is given here:

fnn[x_, y_, z_] := x*Sin[y]*Cos[z]
xr = {1, 2, 3, 4, 5};
yr = {6, 7, 8, 9, 10};
zr = {11, 12, 13, 14, 15};


I want the output in the form,

{{fnn[1, 6, z]},{fnn[2, 7, z]},{fnn[3, 8, z]},{fnn[4, 9, z]},{fnn[5, 10, z]}},


where z varies in the range, {11, 12, 13, 14, 15}. I do not need e.g. fnn[1, 7, z], fnn[2, 8, z] etc.

Clear["Global*"]

fnn[x_, y_, z_] := x*Sin[y]*Cos[z]
xr = {1, 2, 3, 4, 5};
yr = {6, 7, 8, 9, 10};
zr = {11, 12, 13, 14, 15};

{xr, yr}
]


or

Inner[Thread[Inactive[fnn][#1, #2, zr]] &, xr, yr, List]


Result

• Why are the fnn[x,y,z] not evaluated? The output should be like 1*Sin[6]*Cos[11],....... etc? Sep 29, 2023 at 16:21
• I got it. Coz you have added "Inactive" before "fnn". Thanks! Sep 29, 2023 at 16:23
• If these evaluate, then the larger picture would be lost. You can always remove the Inactive when you are satisfied with the output.
– Syed
Sep 29, 2023 at 16:34

You can also use the second and third arguments of Thread combined with MapThread as follows:

Map[Thread] @ Thread[FOO[xr, yr, zr], List, 2]


Map[Thread] @ Thread[FOO[xr, yr, zr], List, 2] /. FOO -> fnn


Alternatively, use

ReleaseHold @ Map[Thread] @ Thread[Hold[fnn][xr, yr, zr], List, 2]


to get the same result.

Since all components of fnn (Times, Sin, Cos) are Listable, you can simply map fnn[xr, yr, #] & on zr:

Map[fnn[xr, yr, #] &] @ zr


Clear[f]
Table[f[xr[[n]], yr[[n]], j], {n, Length[xr]}, {j, zr}]


{{f[1, 6, 11], f[1, 6, 12], f[1, 6, 13], f[1, 6, 14], f[1, 6, 15]}, {f[2, 7, 11], f[2, 7, 12], f[2, 7, 13], f[2, 7, 14], f[2, 7, 15]}, {f[3, 8, 11], f[3, 8, 12], f[3, 8, 13], f[3, 8, 14], f[3, 8, 15]}, {f[4, 9, 11], f[4, 9, 12], f[4, 9, 13], f[4, 9, 14], f[4, 9, 15]}, {f[5, 10, 11], f[5, 10, 12], f[5, 10, 13], f[5, 10, 14], f[5, 10, 15]}}

%/.f->fnn
`

{{Cos[11] Sin[6], Cos[12] Sin[6], Cos[13] Sin[6], Cos[14] Sin[6], Cos[15] Sin[6]}, {2 Cos[11] Sin[7], 2 Cos[12] Sin[7], 2 Cos[13] Sin[7], 2 Cos[14] Sin[7], 2 Cos[15] Sin[7]}, {3 Cos[11] Sin[8], 3 Cos[12] Sin[8], 3 Cos[13] Sin[8], 3 Cos[14] Sin[8], 3 Cos[15] Sin[8]}, {4 Cos[11] Sin[9], 4 Cos[12] Sin[9], 4 Cos[13] Sin[9], 4 Cos[14] Sin[9], 4 Cos[15] Sin[9]}, {5 Cos[11] Sin[10], 5 Cos[12] Sin[10], 5 Cos[13] Sin[10], 5 Cos[14] Sin[10], 5 Cos[15] Sin[10]}}