0
$\begingroup$

I'd like to generate samples of real numbers respecting distributional constraints. I tried (here, for a sample of 17 reals):

NSolve[
 Rationalize[
  {
   0 <= {m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, 
     m15, m16, m17} <= 100,
    Distributed[{m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, 
     m13, m14, m15, m16, m17}, 
    NormalDistribution[
     21.2, (26.87 - 11.68)/(2*Sqrt[2] InverseErf[0.95])]]
   }
  ],
 {m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, 
  m16, m17},
 Reals,
 WorkingPrecision -> 10]

Apparently, I'm not heading in the right direction, because the solver complains with:

NSolve: This system cannot be solved with the methods available to NSolve.

What is a better way of doing that? Thanks!

$\endgroup$
4
  • 1
    $\begingroup$ To generate random variates use {m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17} = RandomVariate[NormalDistribution[21.2, (26.87 - 11.68)/ (2*Sqrt[2] InverseErf[0.95])], 17] While it is unlikely that these would not be in the interval {0, 100}, you can guarantee that by using {m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17} = RandomVariate[ TruncatedDistribution[{0, 100}, NormalDistribution[21.2, (26.87 - 11.68)/(2*Sqrt[2] InverseErf[0.95])]], 17] $\endgroup$
    – Bob Hanlon
    Jan 7 at 0:16
  • $\begingroup$ @BobHanlon Ok, thanks. However, this just samples once, apparently? What if I want to sample until a condition is reached? For instance, resample until 10 numbers are >20 and 7 are <=20 ? $\endgroup$
    – Raoul
    Jan 7 at 0:24
  • 3
    $\begingroup$ dist = NormalDistribution[21.2, (26.87 - 11.68)/(2*Sqrt[2] InverseErf[0.95])]; Join[RandomVariate[ TruncatedDistribution[{20, Infinity}, dist], 10], RandomVariate[TruncatedDistribution[{-Infinity, 20}, dist], 7]] $\endgroup$
    – Bob Hanlon
    Jan 7 at 0:40
  • $\begingroup$ Ah, yes of course! Thanks a bunch! $\endgroup$
    – Raoul
    Jan 7 at 0:43

0

Your Answer

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