# Scan over regions of parameters

I have a function f which takes three arguments x, y and z:

 f[x_,y_,z_] := 2 x + 0.5 y + z


The arguments x, y and z must have a pre-defined domains, for example:

 -1 < x < 1
3 <= y < 7
-3 < z <= 3


I would like to run my function across x,y and z sets corresponding to some pre-defined domains as stated above and extract only those x, y and z sets which produce some arbitrary value, for example:

7, 12, 20 etc.

The expected output I seek is something like:

{{x,y,z}, result}


where {x,y,z} is a set of x,y,z arguments which were passed to my function and result is the associated result which is some pre-defined arbitrary value.

Edit

If I have a function in four parameters instead as f[x_,y_,z_,d_] := 2 x + 0.5 y + z+ d

and I want to run f only over x,y,z regions while fix d at say d=5 . I tried:

f[x_, y_, z_, d_] := 2 x + z + 0.5 y + d

x := Range[1, 5, 1]
y := Range[5, 9, 1]
z := Range[10, 14, 1]
d := 5


data = Outer[f, x, y, z, d]

But it gave output sample:

{{{f[1, 5, 10], f[1, 5, 11], f[1, 5, 12], f[1, 5, 13], f[1, 5, 14]}}}

So it seems doesn’t work. Any help ..

Note that I don't want to set d from the pre definition of the function, because my real calculation are so long and will be difficult to define the fixed parameter each time .

• It is a bit unclear what you are asking. Could you please edit your question and provide more information? Also, the code provided above is not a valid wolfram syntax. It would help if you could provide code that you have tried May 17, 2016 at 10:16
• DensityPlot, is that it? Use the option PlotRange for the second question. May 17, 2016 at 10:18
• Are you trying to make a table of values, or do you want to make a plot? May 17, 2016 at 10:25
• Ok, I added f[x,y,z] to be as Mathematica syntax. Now, I don't want to to make a plot any more, I just want Mathematica to show a table of values for f[x,y,z], epically if I have a function in more than 2 parameters, say four or six parameters, in which each one has a range.
– S.S.
May 17, 2016 at 10:28
• What do you mean by "scan"? Do you just want to compute the values in given grid points? If so, use Table. May 17, 2016 at 10:39

Example:

(*arbitrary data*)
x = Range[1, 5, 1]
y = Range[5, 9, 1]
z = Range[10, 14, 1]


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

(*process*)
data = Outer[f, x, y, z];


Output (sample):

Domain: {1,5,10}, {1,5,11}, {1,5,12}, {1,5,13}, {1,5,14}

EDIT 1

This way may be not the best way how to achieve what you are after. There are some brilliant people out here who can do it with much better aesthetics and efficiency.

domains = Flatten[Outer[List, x, y, z], 2];
results = Flatten[Outer[f, x, y, z], 2];

Select[Transpose[{results, domains}], #[[1]] >= 20 &]


EDIT 2

If you decide to include any additional argument:

Declare domain of interest:

 d = Range[15, 19, 1]


The rest is the same:

domains = Flatten[Outer[List, x, y, z, d], 2];
results = Flatten[Outer[f, x, y, z, d], 2];

Select[Transpose[{results, domains}], #[[1]] >= 20 &]


NOTE:

Make sure to include d in your function declaration!

Reference

• @ E.Doroskevic . data = Outer[f, x, y, z], gives me a sample as: {{16, 17, 18, 19, 20}, {17, 18, 19, 20, 21}}, which are the values of f over x,y,z ranges, but what about the second question, that I want to know which set of x, y, z values give for instance f larger than 20.
– S.S.
May 17, 2016 at 10:51
• Do you mean you want to select only those entries which are >= 20? Or do you want to know which {x,y,z} combination gives f >= 20? May 17, 2016 at 10:55
• To know which {x,y,z} combination gives f >= 20 .
– S.S.
May 17, 2016 at 11:02
• A quick fix would be just embed 5 into your function and leave signature f[x_,y_,z_]. Otherwise, if you want to run f[x_,y_,z_,d_] across all domains of x, y, z and d all you have to do is just provide domain for d and supply Outer function with d - Outer[f, x, y, z, d] May 17, 2016 at 11:23
• @ E.Doroskevic . well, E.Doroskevic thanks any way for your help. Now I try to use your example in case if  f  is a function in one extra parameter which has a fixed value, i.e.,  f[x_ ,y_ ,z_,d_ ]  , and i want to scan, say  f[x,y,z,5] , with changing only x,y,z ..
– S.S.
May 17, 2016 at 11:23