Message Boards Message Boards

GROUPS:

Plot all possible values of a function on a range

Posted 5 months ago
1096 Views
|
14 Replies
|
3 Total Likes
|

Let say I have a function

f[x_,y_,z_]:=x^3+Abs[(E^y)-5z]
x=Range[0,2.65]
y=Range[0,3.86]
z=Range[0,6]

Now I have to plot all possible values of the function f[x,y,z] against z. It will look like to scattered discrete points in f-z plane.

14 Replies
Posted 5 months ago

Hi John,

Is this what you are looking for?

data = Table[{f[x, y, z], z}, {x, 0, 2.65, .1}, {y, 0, 3.86, .1}, {z, 0, 6, .1}] // Flatten[#, 2] &;
ListPlot[data,
  PlotRange -> All, 
  FrameLabel -> (Style[#, 14, Bold] & /@ {"f", "z"}),
  Frame -> True]

enter image description here

Posted 5 months ago

Thanks.

Posted 5 months ago

When applied the same approach for a complicated function which has 14 variables the program seems extremely slow taking several hours. Is there any alternative approach for this kind of problem?

Posted 5 months ago

Hi John,

It really depends on the granularity you need for each of the 14 variables, and on the time it takes for the complex function to execute. If the complex function can be compiled, you can try that. Reducing granularity will also speed up the generation of the table. You could also experiment with ParallelTable if you have access to multiple kernels.

Posted 5 months ago

I think the problem using 14 variables is with granularity which you have mentioned ( even reducing the granularity significantly it is creating 10^6 orders of datas which are taking too much time to plot) . But is this possible to create a random data set of those 14 variables with less no of points, like (a, b, c, ....) each having random values with range specified and I want to generate only 200 of those dataset and then plot them.

Posted 5 months ago

You can (quickly) get a 200x14 array of RandomReal in the range 0. to 6., like this:

RandomReal[{0, 6}, {200, 14}];
Posted 5 months ago

Hi John,

Here is one way to generate random values with specific ranges for each variable. Using the ranges from your original question:

points := {RandomReal[{0, 2.65}], RandomReal[{0, 3.86}], RandomReal[{0, 6}]};
Table[points, 200]
Posted 5 months ago

Thanks for your answer. Can you show me how this random number can be put in a code relating the function variables and how to get a plot as like your first answer.

Posted 5 months ago

Here is one way

ClearAll[f, points]

f[x_, y_, z_] := x^3 + Abs[(E^y) - 5 z]
points := {RandomReal[{0, 2.65}], RandomReal[{0, 3.86}], RandomReal[{0, 6}]}

data = Table[{f @@ points, Last@points}, 200];

ListPlot[data]
Posted 5 months ago

Thanks a lot. But I have a simple doubt how the code will understand z will take the Last points , i.e. how to tell the code which RandomReal[] block specify which variable. It is required when I have to plot f vs x rather than f vs z.

Posted 5 months ago

The values returned by points, list of {x, y, z}, are passed to f in the same order. Simple example

SeedRandom[123];
point = points
(* {1.20766, 3.77441, 5.65929} *)

f@@point
(* 17.0366 *)

Is the same as

f[point[[1]], point[[2]], point[[3]]]
(* 17.0366 *)

To plot f[x, y, z] vs x, generate the table as

{f @@ points, First@points}

To plot against y

{f @@ points, points[[2]]}
Posted 5 months ago

Thanks, Rohit,

But the ordinary parameter scan and random parameter scan plot differs significantly. Is this possible to get an overall similar plot using random scan also than it will be easy to get the data interpretation with lesser no of points.

Posted 5 months ago

Hi, Rohit

Can you help me to do the same thing using Subdivision array by generating some points corresponding to each variables and generate the function values at each set

May be something like this one:

f[x_, y_, z_] := x^3 + Abs[(E^y) - 5 z]   
Plot3D[Table[f[x, y, z], {z, 0, 6, 0.5}], {x, 0, 2.65}, {y, 0, 3.86}]

enter image description here

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract