# Evaluating a function that takes numerical arguments over a given list/table

I have a given list of some numbers e.g.

a = {0, 0.233, 0.65, 1.56};


I want to evaluate a function

Func[x_?NumberQ,y_?NumberQ,z_?NumberQ]


where one variable z takes its values from the specified list a.

How do I do this in best way ?

• The best way depends on the function, its intended use, and other goals. – Michael E2 Aug 2 '18 at 18:57

Data

a = Range[5]
(* {1, 2, 3, 4, 5} *)


## Listable

SetAttributes[func, Listable];
func[x_?NumberQ, y_?NumberQ, z_?NumberQ] = f[x, y, z];
func[x, y, a]
(* {func[x, y, 1], func[x, y, 2], func[x, y, 3], func[x, y, 4], func[x, y, 5]} *)


## Map

f[x, y, #] & /@ a
(* {f[x, y, 1], f[x, y, 2], f[x, y, 3], f[x, y, 4], f[x, y, 5]} *)


## Thread

Thread[f[x, y, a]]
(* {f[x, y, 1], f[x, y, 2], f[x, y, 3], f[x, y, 4], f[x, y, 5]} *)


## Table

Table[
f[x, y, z]
, {z, a}
]
(* {f[x, y, 1], f[x, y, 2], f[x, y, 3], f[x, y, 4], f[x, y, 5]} *)


If you have fixed, known values x1 and y1 for the first variables, then how about the following?

a={0, 0.233, 0.65, 1.56};
Func[x1,y1,#]&/@a

• It worked. Thanks !! – Prag Aug 3 '18 at 10:42

Define your function with just $x$ and in the body refer to x[[7]] (or multiple entries, or whatever components of $x$ are used as $z$).

• Thank you !! I need the argument i of x[[i]] to run from 1... length[A]. So I need to create a table in the end which implements the following: B = Table[Func[x0,y0,z] : z goes from A[1] to A[N] ]. – Prag Aug 2 '18 at 17:43