New answers tagged

5

For the sake of demonstration, let us suppose f[r_Real, p_Real, t_Integer] := r Sin[p t] With[{n = 10}, triples = Transpose[ {RandomReal[{0, 1}, n], RandomReal[{0, 2 Pi}, n], RandomInteger[{1, 10}, n]}]]; Note that this last definition can generate a list of triples of any size by changing the value given to n. Now, N. J. ...


5

If you want to create a ProbabilityDistribution for a two-point random variable, here is one way to do so: x1 =. x2 =. p1 =. twoPointRV = TransformedDistribution[y x1 + (1 - y) x2, y \[Distributed] BinomialDistribution[1, p1]] Now you can use twoPointRV symbolically as a ProbabilityDistribution: mean = Expectation[x, x \[Distributed] twoPointRV] (* ...


2

You can specify such a ProbabilityDistribution by using DiracDelta which have some interesting properties: x1=1; x2=0; p1=.3; p2=.7; d = ProbabilityDistribution[p1 DiracDelta[x - x1] + p2 DiracDelta[ x-x2], {x, -Infinity, Infinity}]; RandomVariate[d] Expectation[x, x \[Distributed] d] ProbabilityDistribution will automatically transfrom your ...


0

You might want to look at HistogramDistribution. It provides a piecewise constant PDF. Since it is a distribution object, you can use RandomVariate, Mean, etc. on it.


5

happy fish gave the right answer, but sometimes it's fun to go oldschool. You can use rejection sampling and a While loop list = {}; While[Length@list <= 10, list = DeleteDuplicates@Append[list, RandomInteger[100]]]


9

RandomSample[Range[0, 100], 10]


0

This approach is quite different from my previous answer. Therefore I decided to separate them for clarity. Let us write first a function that for a given sample returns the probability to obtain it via the random process described in the original post. prob[ncol_, max_, len_, conf_] := Module[{cnt = ConstantArray[max, ncol], ucnt, p = 1}, Do[ ...


1

If we ignore random sampling, this is a simple question of Boolean satisfiability: Module[{m, n, greens, matrix, sol}, m = 8; n = 5; greens = 20; matrix = Array[c, {m, n}]; sol = matrix /. First@FindInstance[ And @@ (BooleanCountingFunction[Length@# - 2, Length@#] @@ # & /@ matrix) && And @@ (...


2

Here's a quick-and-dirty method that does what (I think) you're after: makearr[{n_, m_}, p_] := Module[{base = PadLeft[ConstantArray[1, Round[n m p]], n m], cand}, While[(cand = ArrayReshape[RandomSample@base, {n, m}]; Max[Total[cand]] > n - 2 || Max[Total /@ cand] > m - 2)]; Position[cand, 1]]; Example usage: makearr[{5, 5}, .4] {{...


16

Yes you can. Below is a fairly general, Mathematica-compiled, fast and robust version. Examples 1. Michaelis-Menten kinetics Michaelis-Menten kinetics for enzyme-directed substrate conversion. The enzyme (e) converts the susbtrate (s) through an enzyme-substrate complex (c) to the product (p). For comparison, I've included the deterministic ODE system ...


1

This appears to be a bug. Histogram shows result of 100K RV on PascalDistribution[1,1/50] for 100k batch using RandomVariate[...,100000] (blue) and generating a table of 100k single calls (default chicken-poop-and-mud jaundice beige): Thanks to Karsten for verification and Jim for histogram idea.


1

In the t1 case Random`DistributionVector[PascalDistribution[1, 1/50], 10000, ∞] is evaluated and in the t2 case Random`DistributionVector[PascalDistribution[1, 1/50], 10, ∞] The definition of this function contains a Which statement. Its first test is True for 10000 and False for 10. Its second test (there are only two) is True. For your parameters ...


1

Just an extended comment: Rather than a consistent shift for the values in the minimum values for t2, it appears that the distribution is completely different than for t1, t3, and t4. Here's a figure showing that: h[x_, label_] := Histogram[Min /@ x, {1}, "PDF", PlotRange -> {{0, 30}, {0, 0.20}}, PlotLabel -> Style[label, Bold, Larger]] ...



Top 50 recent answers are included