help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: radial gaussian distribution


From: Mike Miller
Subject: Re: radial gaussian distribution
Date: Tue, 20 Sep 2005 12:21:43 -0500 (CDT)

On Tue, 20 Sep 2005 address@hidden wrote:

Be careful, Roberto! The "solution"

 r = R*randn(N,1);

(followed by "x = r.*sin(phi); y = r.*cos(phi);" to generate corresponding x and y coordinates) posted by Shai Ayal is in fact not correct for what you want!

I think it was correct. The Euclidian distance of (x,y) to (0,0) is r, as Roberto requested.

I think the disagreement here is because of one 'n' above. This would not work...

r = R*rand(N,1);

...and if used like this,

phi=rand(N,1)*2*pi;
x = sqrt(-2*log(r)).*sin(phi);
y = sqrt(-2*log(r)).*cos(phi);

it would produce bivariate normal (x,y):

http://mathworld.wolfram.com/Box-MullerTransformation.html

but this...

r = R*randn(N,1);
phi=rand(N,1)*2*pi;
x = r.*sin(phi);
y = r.*cos(phi);

Seems to do what was requested because 'r' is the distance from (x,y) to (0,0) and it has a normal distribution.

Mike



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]