Random vector on a sphere: Difference between revisions
Jump to navigation
Jump to search
Carl McBride (talk | contribs) (New page: ==References== #[http://links.jstor.org/sici?sici=0003-4851%28197204%2943%3A2%3C645%3ACAPFTS%3E2.0.CO%3B2-%23 George Marsaglia "Choosing a Point from the Surface of a Sphere", The Annals o...) |
No edit summary |
||
Line 1: | Line 1: | ||
Fortran 90 implementation from Ref. 2. ran() is some [[Random_numbers | randon number generator]]: | |||
<small><pre> | |||
! The following is taken from Allen & Tildesley, p. 349 | |||
! Generate a random vector towards a point in the unit sphere | |||
! Daniel Duque 2004 | |||
subroutine random_vector(vctr) | |||
implicit none | |||
real, dimension(3) :: vctr | |||
real:: ran1,ran2,ransq,ranh | |||
real:: ran | |||
do | |||
ran1=1.0-2.0*ran() | |||
ran2=1.0-2.0*ran() | |||
ransq=ran1**2+ran2**2 | |||
if(ransq.le.1.0) exit | |||
enddo | |||
ranh=2.0*sqrt(1.0-ransq) | |||
vctr(1)=ran1*ranh | |||
vctr(2)=ran2*ranh | |||
vctr(3)=(1.0-2.0*ransq) | |||
end subroutine random_vector | |||
</pre></small> | |||
==References== | ==References== | ||
#[http://links.jstor.org/sici?sici=0003-4851%28197204%2943%3A2%3C645%3ACAPFTS%3E2.0.CO%3B2-%23 George Marsaglia "Choosing a Point from the Surface of a Sphere", The Annals of Mathematical Statistics '''43''' pp. 645-646 (1972)] | #[http://links.jstor.org/sici?sici=0003-4851%28197204%2943%3A2%3C645%3ACAPFTS%3E2.0.CO%3B2-%23 George Marsaglia "Choosing a Point from the Surface of a Sphere", The Annals of Mathematical Statistics '''43''' pp. 645-646 (1972)] | ||
#Daan Frenkel and Berend Smit "Understanding Molecular Simulation: From Algorithms to Applications" p. 410 Academic Press (1996), algorithm based on: | |||
# M.P. Allen (Author) and D.J. Tildesley "Computer Simulation of Liquids" p. 349 Clarendon Press (1989) | |||
[[category: random numbers]] | [[category: random numbers]] | ||
[[category: computer simulation techniques]] | [[category: computer simulation techniques]] |
Revision as of 10:10, 30 October 2007
Fortran 90 implementation from Ref. 2. ran() is some randon number generator:
! The following is taken from Allen & Tildesley, p. 349 ! Generate a random vector towards a point in the unit sphere ! Daniel Duque 2004 subroutine random_vector(vctr) implicit none real, dimension(3) :: vctr real:: ran1,ran2,ransq,ranh real:: ran do ran1=1.0-2.0*ran() ran2=1.0-2.0*ran() ransq=ran1**2+ran2**2 if(ransq.le.1.0) exit enddo ranh=2.0*sqrt(1.0-ransq) vctr(1)=ran1*ranh vctr(2)=ran2*ranh vctr(3)=(1.0-2.0*ransq) end subroutine random_vector
References
- George Marsaglia "Choosing a Point from the Surface of a Sphere", The Annals of Mathematical Statistics 43 pp. 645-646 (1972)
- Daan Frenkel and Berend Smit "Understanding Molecular Simulation: From Algorithms to Applications" p. 410 Academic Press (1996), algorithm based on:
- M.P. Allen (Author) and D.J. Tildesley "Computer Simulation of Liquids" p. 349 Clarendon Press (1989)