1

Here's my problem. I would like to test a whole bunch of random function parameter values for certain conditions, and if they meet all of these conditions, I'd like to add them to a table or an array or something so that I can then plot the points (ignoring the sets of values that do not meet all of these conditions). Here are a few specifics:

My conditions rely on three parametric functions:

0 < (H[m, s][u] /. sol) && 
0 < (S[m, s][u] /. sol) < 4 Pi && 
-4 Pi < (SH[m, s][u] /. sol) < 4 Pi

I want to test random values for m and s across the function domain u = {10^3, 10^18}.

m = RandomInteger[{300, 2200}];
s = RandomReal[{-1, 1}];

I'd like to store (plot) lots of random points that satisfy the conditions, and scrap the rest. What's the best way to do this?

1 Answers1

1

I'd propose something like the following:

synthetic conditions (note the := here):

conditions := m < 1000 && -0.5 < s < 0.5 && PrimeQ[u]

and a Do loop:

out = {};
Do[SeedRandom[];
 m = RandomInteger[{300, 2200}];
 s = RandomReal[{-1, 1}];
 If[conditions, {AppendTo[out, {m, s, u}], Continue[]}, 
  Continue[]], {u, 10^3, 10^4}
 ]

Part of the output:

{{556, 0.321089, 1009}, {575, 0.345256, 1013}, {600, -0.0361481, 1103}, {522, 0.0317783, 1277}, {746, -0.40744, 1321}, {325, -0.187146, 1367}, {447, 0.130137, 1483}, {360, -0.284384, 1487}, {357, 0.0764024, 1489}, {661, 0.473819, 1571}, {713, 0.389343, 1601}, {373, -0.00995126, 1607}, {867, -0.448495, 1619},...}

b.gates.you.know.what
  • 20,103
  • 2
  • 43
  • 84
corey979
  • 23,947
  • 7
  • 58
  • 101
  • Thanks for the lead! However, I need the points {m,s} which satisfy the entire domain given for u. That's the tricky part in my opinion. I can't just test random values as you've done. I need the conditions to be satisfied over the entire domain. – Ash Arsenault Sep 08 '16 at 18:24
  • I don't really get it. You explicitly wrote "test random values for m and s", and "m = RandomInteger[{300, 2200}]; s = RandomReal[{-1, 1}];'". You can of course change the range ofufrom{u, 10^3, 10^4}` in my exaple to what you desire. – corey979 Sep 08 '16 at 18:32
  • Am I incorrect in understanding that with the code you've provided, only one value of 'u' is tested with each m-s pair? – Ash Arsenault Sep 08 '16 at 18:34
  • Yes. How many do you want? E.g., m should take all integer values from 300 to 2200? – corey979 Sep 08 '16 at 18:35
  • 'm' and 's' can be random. I don't need every value for those -- that's fine. It's just that for every random pair of 'm' and 's' values, the conditions must be satisfied over all 'u' in my domain. Does that make sense? Sorry, I'm really struggling to express my needs. Haha. – Ash Arsenault Sep 08 '16 at 18:38
  • Ah, ok, now I understand. Give me a moment. But btw, even for a single pair m-s you want to test $10^{18}$ values of u. You know that will take thousands of yours on a desktop computer? I recently worked on an algebraically simple task that would require a supercomputer with 50,000 cores to run for a month to test all $10^{16}$ instances of interest... – corey979 Sep 08 '16 at 18:43
  • You could just take the random generation of m and s out of the Do. – corey979 Sep 08 '16 at 18:46
  • I seem to be able to plot the function just fine in a matter of seconds over that domain, so my intuition tells me that it shouldn't be that much harder to check the range. But I could be wrong. I'm currently using FindMinValue and FindMaxValue as intermediate steps in the Do loop, but I'm not having any luck. – Ash Arsenault Sep 08 '16 at 19:14