New answers tagged

2

whenever you use Manipulate, use TrackedSymbols to tell it which symbols to track Manipulate[m = RandomPrime[d]; {m, d}, {d, {20, 50}, SetterBar}, TrackedSymbols :> {d}] Without this, it will track each symbol in its expression and if any changes, it will re-evaluate again automatically until no more changes are detected.


9

Given your specific example, nothing is "wrong" with ProbabilityDistribution. @MarcoB and @J.M.'stechnicaldifficulties have given the issue: ProbabilityDistributon is more limited with multivariate distributions it knows and your bivariate distribution is not a standard or common distribution. One can take random samples by finding the marginal ...


1

You can use Catch and Throw: SeedRandom[0]; Block[{a, b, f, g}, exception = Catch[ Do[ a = RandomReal[{-1, 1}, {2, 2}]; a = a\[Transpose].a; b = RandomReal[{-1, 1}, {2, 2}]; b = b\[Transpose].b; f[x_, y_] := Det@MatrixFunction[Log, (x + y)/2] - Log[Det[x.y]]/2; g[x_, y_] := Det[x + y]^(1/2) - Det[x]^(1/2) - Det[y]^(1/2); ...


2

Supposing that you have defined your function f(a,b) and g(a,b), and that a and b are to be 2 by 2 matrices: Select[Table[a = RandomReal[{-1, 1}, {2, 2}]; b = RandomReal[{-1, 1}, {2, 2}]; If[f[a, b] - g[a, b] < 0, {a, b}], {i, 1000}], #=!=Null &] This lists all the {a,b} for which the condition holds. You can save a bit (...


3

just in case someone is not interested in real words and wants something faster StringJoin@RandomChoice[Flatten@{Alphabet[], " "}, 100000]


0

One can exploit the equivalence of evaluating three-term recurrence relations with repeated multiplication of $2\times 2$ matrices for this task. Just like in ubpdqn's solution, I use RandomChoice[] to generate a bunch of $\pm1$ multipliers all at once: BlockRandom[SeedRandom[42, Method -> "MersenneTwister"]; (* for reproducibility *) With[{n ...


1

I'm assuming you want to vary the Bernoulli parameter p depending on the pixel grayscale value. Darker areas of the image are more likely to generate a black pixel and lighter areas more likely to be white. img = Import["ExampleData/ocelot.jpg"]; dat = ImageData[img]; result = Image[ Map[RandomVariate[BernoulliDistribution[#]] &, dat, {2}]] The ...


Top 50 recent answers are included