# ProbabilityDistribution fails for square root

I would like to sampling data from a distribution Sqrt[x^2 + y^2]. I used the code as follows:

a = ProbabilityDistribution[Sqrt[x^2 + y^2], {x, 0, 1}, {y, 0, 1}];
RandomVariate[a, 10]

However, mathematica fails to produce the result.

If I use this code, then it works.

a = ProbabilityDistribution[x^2 + y^2, {x, 0, 1}, {y, 0, 1}];
RandomVariate[a, 10];

It seems that these two are not so different, except for the second one does not have square root. Can anyone explain this?

• In terms of a tractable formula, a square root can make a big difference. But in any event, Mathematica 10.4 gives me a warning rather than "fails to produce the result": For Mathematica 10.4 I get the following warning: "Sampling from ProbabilityDistribution[$\sqrt{x1^2+x2^2},\{x1, 0 , 1\}, \{x2, 0, 1\}$] is not implemented."
– JimB
Commented Aug 31, 2018 at 5:24
• Neither the pdf $f(x,y) = \sqrt(x^2 + y^2)$ nor the pdf $g(x,y) = x^2 + y^2$ is valid or well-defined, as neither integrates to unity. Commented Aug 31, 2018 at 13:07

Sqrt[x^2 + y^2], {x \[Distributed] UniformDistribution[{0, 1}],
y \[Distributed] UniformDistribution[{0, 1}]}];

SeedRandom[0]

(* {0.671686, 1.03103, 1.13352, 0.855141, 0.984159, 1.23482, 0.908538, 0.637849, \
0.551954, 0.735437} *)

Note that Sqrt[x^2+y^2] is a scalar and unlike your second example, RandomVariate[a, 10] should return a list of 10 scalars rather than a list of 10 pairs.

• I don't follow your comment that $\sqrt(x^2 + y^2)$ is scalar: the pdf $f(x,y) = \sqrt(x^2 + y^2)$ defines a bivariate space, and random variates drawn from that distribution should be bivariate pairs. [ If the OP is after a scalar -- well ... who knows ... maybe he is ... but that is not what he has set up using ProbabilityDistribution Commented Aug 31, 2018 at 13:10