3
$\begingroup$

First consider vectors of unit length, say on the unit sphere. Now I want to give some magnitude to these vectors and I want the magnitude to be chosen from the normal distribution. In one dimension that is easy:

RandomReal[NormalDistribution[0,x]]

However, if my vector is arbitrarily pointed I cannot take from this distribution since I cannot have a negative magnitude.

The only way I can think of giving the vector a normal distribution of lengths is by using

RandomReal[HalfNormalDistribution[y]]

which forces the randomly chosen quantity to be > 0. Does this seem like the proper procedure?

$\endgroup$
4
  • 1
    $\begingroup$ Why not Normalize[] the vectors to have unit length, and then multiply the components with RandomReal[NormalDistribution[0,x]]? (I haven't posted as an answer since you make no mention of the distribution the vectors themselves are supposed to follow...) $\endgroup$ Commented Feb 3, 2012 at 2:57
  • $\begingroup$ @J.M The vectors orientations are distributed over some portion of the sphere (with azimuthal symmetry and symmetric around polar angle of 90). So I think the negative part of the vectors is accounted for already through the angle distribution and that's why I didn't use the full normal distribution. $\endgroup$
    – BeauGeste
    Commented Feb 3, 2012 at 3:05
  • $\begingroup$ From Mma documentation on RandomReal I would have thought that you needed RandomVariate[...]; but, to my surprise, RandomReal[NormalDistribution[0,1]] generates standard normal random numbers,i.e., RandomReal does accept distribution functions as the first argument:) $\endgroup$
    – kglr
    Commented Feb 3, 2012 at 3:16
  • $\begingroup$ @BeauGeste I did the calculation and realized the normal distribution of lengths and the normal distribution of coordinates are actually the same thing (assuming a spherically symmetric angular distribution), which is why I deleted my comment ;-) $\endgroup$
    – David Z
    Commented Feb 3, 2012 at 3:19

2 Answers 2

7
$\begingroup$

Technically, the normal distribution is defined on the real line, $\mathbb{R}$, but vector lengths are nonnegative numbers, elements of $\mathbb{R}_{0+}$. So you can't really have the lengths of your vectors satisfy a normal distribution. You have to choose a distribution for the lengths that has the correct domain, $\mathbb{R}_{0+}$.

One thing you can do, and my best guess at what you really want, is to use the restriction of the normal (or half-normal) distribution to the nonnegative numbers. That would be accomplished exactly like you said, by choosing the length from HalfNormalDistribution.

If the angular distribution of the vectors (the distribution of their directions) has reflection symmetry, in the sense that a vector is just as likely to point in any particular direction $\hat{n}$ as it is to point in the opposite direction $-\hat{n}$, then you actually can multiply the unit vectors you have by random numbers chosen from the full normal distribution. If the random number is negative, it will switch the direction of your vector, but since $P(\hat{n}) = P(-\hat{n})$, the probability of switching any one direction to the opposite direction is the same as the probability of switching the opposite direction to the original direction. Those two effects cancel out. If the angular distribution is not symmetric, however, then using the full normal distribution will have the effect of symmetrizing it, i.e. you'll wind up with a new distribution of directions $P'$ such that $P'(\hat{n}) = \frac{1}{2}\bigl(P(\hat{n}) + P(-\hat{n})\bigr)$.

$\endgroup$
5
  • $\begingroup$ thanks; had never seen the half-normal before was was wary of using it. That is a good point on the symmetry. The reason I am trying to make these vectors is that I start out with normal fields constrained in x-y plane; that is easy - can do normal distribution for x and y components. What I really want is to allow the plane the fields lie in to be distributed out of the x-y plane; the fields keep the same distribution wrt to their plane but not to the x-y plane. With your help, I think I now have the solution to describing these fields. $\endgroup$
    – BeauGeste
    Commented Feb 3, 2012 at 4:07
  • $\begingroup$ Ah, I see. For generating vectors randomly distributed in an arbitrary plane, you can still choose components $x$ and $y$ from a normal distribution, but instead of using $\hat{x} = (1,0,0)$ and $\hat{y} = (0,1,0)$ as your basis vectors, you use an orthonormal basis $\hat{a},\hat{b}$ for your plane, and form the final vector as $x\hat{a} + y\hat{b}$. That may be cleaner than choosing the magnitude from a half-normal distribution and whatever you're doing to get the directional distribution. $\endgroup$
    – David Z
    Commented Feb 3, 2012 at 5:41
  • $\begingroup$ Actually I tried that originally and ran into some numerical errors when using Gram-Schmidt process (the random vectors occasionally are near parallel). This may be a future question since I would like to check the accuracy of using the (Half)NormalDistribution method discussed in this present question $\endgroup$
    – BeauGeste
    Commented Feb 3, 2012 at 18:50
  • $\begingroup$ Huh, so how are you determining the plane in which you want these vectors to lie in the first place? $\endgroup$
    – David Z
    Commented Feb 3, 2012 at 18:54
  • $\begingroup$ I choose those two vectors randomly over a swath near the equator. $\endgroup$
    – BeauGeste
    Commented Feb 3, 2012 at 20:26
2
$\begingroup$

Theorem. This works pretty well:

randomVector := RandomVariate[NormalDistribution[], 3];

Proof. Create a large data set and display it for the fun of it.

points = Table[randomVector, {100000}];
Graphics3D[{PointSize[0], Point[points]}]

enter image description here

Statistics time! Histogram plus Maxwell distribution etc,

norms = Norm /@ points;
hlist = HistogramList[norms];
Show[
    Histogram[norms],
    Plot[\[Pi] Max[hlist[[2]]] r^2 PDF[NormalDistribution[], r], {r, 0, Max[hlist[[1]]]}, PlotStyle -> ColorData[1][2]]
]

enter image description here

Looks pretty good to me. $\square$

(David Zaslavsky's comment is of course still valid, thete's no normal distribution on $\mathbb R^+$.)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.