0
$\begingroup$

I want to solve an inequality e.g.

RegionPlot3D[x^2 + y^2 + z^2 > 300, {x, 2, 9}, {y, 3, 10}, {z, 4, 12}]

and store x, y, z values for which this inequality gets satisfied in a table with x value y value and z value entries. I would like to use that table to plot any two variables among x, y, z. How can I extract the data values from the plot?

$\endgroup$
  • $\begingroup$ Do you want integer solutions? Otherwise, there are infinitely many solutions. $\endgroup$ – mjw Mar 17 at 18:02
  • $\begingroup$ Thanks rohit for editting $\endgroup$ – Immy Salam Mar 18 at 8:14
  • $\begingroup$ No , i want all such many solution, which will later cover a region between two variables. I have given a fractional step size for each range. Can you tell me how fast is this method, because my data points could be many many more in the original program. Earlier when i did the region3D plot, for my original program, it takes a time like 20 mints. $\endgroup$ – Immy Salam Mar 18 at 8:28
0
$\begingroup$

Here is code to generate a list of integer solutions in the ranges you provided:

Do[If[x^2 + y^2 + z^2 > 300, Print[{x, y, z}]], {x, 2, 9}, {y, 3, 10}, {z, 4, 12}]

Here is the output:

enter image description here

Better yet, to store the values in Q:

Q = {}; 
Do[
   If[x^2 + y^2 + z^2 > 300, Q = Join[Q, {{x, y, z}}]], 
   {x, 2, 9}, {y, 3, 10}, {z, 4, 12}
]

Here is Q:

Q // TableForm

enter image description here

$\endgroup$
  • $\begingroup$ Thanks for the code, i tried it as such , and that is all i want. As i have just given an example here. The original problem is a bit more complex, going to apply the same logic there. $\endgroup$ – Immy Salam Mar 18 at 8:24
  • $\begingroup$ Thanks a lot mjw, it works. $\endgroup$ – Immy Salam Mar 18 at 18:06
  • $\begingroup$ You are welcome! $\endgroup$ – mjw Mar 19 at 2:14
  • $\begingroup$ Dear mjw, As I am running this code from 7 days on my i7 machine, because the function i am using a complicated one, is there any way to make this faster, by means of parallelization, or changing it to C. $\endgroup$ – Immy Salam Mar 28 at 12:06
  • $\begingroup$ Which code? Please post your code and perhaps we'll see a way to speed it up ... $\endgroup$ – mjw Mar 28 at 12:45
0
$\begingroup$

You can use Part to get the coordinates used by RegionPlot:

rp = RegionPlot3D[x^2 + y^2 + z^2 > 200, {x, 2, 9}, {y, 3, 10}, {z, 4, 12}];

Coordinates:

coords = rp[[1, 1]];

Show coords with the region surface:

Show[RegionPlot3D[x^2 + y^2 + z^2 > 200, {x, 2, 9}, {y, 3, 10}, {z, 4, 12}, 
  PlotStyle -> Opacity[.1], Mesh -> None, BoundaryStyle -> None], 
 ListPointPlot3D[coords]]

enter image description here

$\endgroup$
0
$\begingroup$

To extract the actual values use in the plot:

plot = RegionPlot3D[x^2 + y^2 + z^2 > 300, {x, 2, 9}, {y, 3, 10}, {z, 4, 12}];
Cases[plot, _GraphicsComplex][[1, 1]] // Short

(* {{7.5,9.98755,12.},<<1084>>,{8.77091,9.58138,11.4544}} *)

Update

Not sure exactly what you mean by "in table form". data is a list of lists which is how a table is usually represented in WL.

data = Cases[plot, _GraphicsComplex][[1, 1]];

You can save it to a file

Export["data.dat", data];

Read it back later

data2 = Import["data.dat"];
data2 == data
(* True *)

Plot all of the x, y values

ListPlot[data[[All, {1, 2}]]]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks for the code, But i don't want them to be displayed or saved like this. I want a columns of x , y ,z data values in a table form to save that table for further analysis. Can you please suggest the way out and extended this thread more, i will appreciate your value time and suggestions. $\endgroup$ – Immy Salam Mar 18 at 8:17
0
$\begingroup$

mjw This is the code

sv11ss[g_, mx_, m\[Psi]_] =0. + (0.0242711 g^4 m\[Psi]^2)/((26.0127 + 1. g^4) mx^4 -  208.102 mx^2 m\[Psi]^2 + 416.204 m\[Psi]^4) + (0.075676 g^4(-4.50051*10^8-15000.9 m\[Psi]^2 + m\[Psi]^4))/((-15000.9 + m\[Psi]^2) ((26.0127+1. g^4) mx^4 - 208.102 mx^2 m\[Psi]^2 + 416.204 m\[Psi]^4)) + (0.380504 (0. + 0.00043828 g^8 mx^4 m\[Psi]^4 +g^4 (0.0114009 mx^4 m\[Psi]^4 - 0.0912069 mx^2 m\[Psi]^6 + 0.182414 m\[Psi]^8)))/(m\[Psi]^2 ((0.61685 + 0.0237134 g^4) mx^4 - 4.9348 mx^2 m\[Psi]^2 + 9.8696m[Psi]^4)^2) + (676.662 (0. + 0.0000715353 g^8 mx^8 m\[Psi]^4 + g^4 (0.00186083 mx^8 m\[Psi]^4 - 0.0148866 mx^6 m\[Psi]^6 + 0.0297732 mx^4 m\[Psi]^8)))/(mx^4 m\[Psi]^2 ((26.0127 + 1. g^4) mx^4 - 208.102 mx^2 m\[Psi]^2 + 416.204 m\[Psi]^4)^2)

Then Finally i want to solve this for

mQ = {};Do[If[+0.0001257367 mx >= g + 0.15128504 && 1.0456*^-9 <= sv11ss[g, mx, m\Psi] <= 1.06676*^-9,Q = Join[Q, {{g, mx, m\Psi}}]], {g, 0.01, 0.5, 0.001}, {mx, 500.,10000., 0.5},{m\Psi,300,7000}]Export["newdelmxgFit(0.5).txt", Q, "Table"] // AbsoluteTiming\\

Can i ma ke this kind of code faster

$\endgroup$
  • $\begingroup$ Well, just to see how long this is going to take ..., If we let $g$ vary from 0 to 0.5 in steps of .1, mx vary from 500 to 1000 in steps of 5, $m\psi$ vary from 300 to 7000, this will take 3.165 seconds. Your version should take 18.5 * 10^5 as long. That is about 6 million seconds. $\endgroup$ – mjw Mar 29 at 1:56
  • $\begingroup$ Also, your use of Join may not be efficient, especially for such a large list that is increasing with each iteration. $\endgroup$ – mjw Mar 29 at 1:59
  • $\begingroup$ Perhaps we can calculate how much memory you are using. Is there any way to scale down this problem? $\endgroup$ – mjw Mar 29 at 2:00
  • $\begingroup$ There is no way, I tried a test code for smaller points, with more step size but it misses then some solutions in between. You mean this will run for 69 days, for the step size that I have given. omg. How can i calculate the time for my code, for how long it will run? $\endgroup$ – Immy Salam Mar 29 at 10:08
  • $\begingroup$ I would suggest scaling it down a bit. Either that or set up a few dozen computers in parallel. I believe you need to think more about the results you need, maybe either reduce the step sizes, or focus in on a smaller region, or both. Also, maybe you or somebody else can come up with more efficient code. How important is the result? Is it worth waiting over two months (and will you have enough memory) to store it all? $\endgroup$ – mjw Mar 29 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.