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.
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}]
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]
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.
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
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?
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.
ParallelTable
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.
You can (quickly) get a 200x14 array of RandomReal in the range 0. to 6., like this:
RandomReal
RandomReal[{0, 6}, {200, 14}];
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]
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.
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]
Thanks.