Random vector on a sphere: Difference between revisions
		
		
		
		Jump to navigation
		Jump to search
		
| Carl McBride (talk | contribs) No edit summary | Carl McBride (talk | contribs)  m (Clarified a reference) | ||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| The ability to generate a randomly orientated vector is very useful in [[Monte Carlo]] simulations of anisotropic [[models]] | The ability to generate a randomly orientated vector is very useful in [[Monte Carlo]] simulations of anisotropic [[models]] | ||
| or molecular systems. | or molecular systems. | ||
| ==Marsaglia algorithm==   | ==Marsaglia algorithm==   | ||
| This is the algorithm proposed by George Marsaglia ( | This is the algorithm proposed by George Marsaglia  <ref name="Marsaglia">[http://dx.doi.org/10.1214/aoms/1177692644 George Marsaglia "Choosing a Point from the Surface of a Sphere", The Annals of Mathematical Statistics '''43''' pp. 645-646 (1972)]</ref> | ||
| *Independently generate V<sub>1</sub> and V<sub>2</sub>, taken from a uniform distribution on (-1,1) such that   | *Independently generate V<sub>1</sub> and V<sub>2</sub>, taken from a uniform distribution on (-1,1) such that   | ||
| :<math>S=(V_1^2+V_2^2) < 1</math> | :<math>S=(V_1^2+V_2^2) < 1</math> | ||
| *The random vector is then ( | *The random vector is then (Eq. 4 in <ref name="Marsaglia"> </ref> ): | ||
| :<math>\left(2V_1 \sqrt{1-S},~ 2V_2 \sqrt{1-S},~ 1-2S\right)</math> | :<math>\left(2V_1 \sqrt{1-S},~ 2V_2 \sqrt{1-S},~ 1-2S\right)</math> | ||
| ==Fortran 90 implementation== | ==Fortran 90 implementation== | ||
| This Fortran 90 implementation is adapted from  | This Fortran 90 implementation is adapted from Refs. <ref>[http://molsim.chem.uva.nl/frenkel_smit Daan Frenkel and Berend Smit "Understanding Molecular Simulation: From Algorithms to Applications", Second Edition (2002)] Algorithm 42 (p. 578)</ref> and <ref>[http://www.oup.com/uk/catalogue/?ci=9780198556459 M. P. Allen and D. J. Tildesley "Computer Simulation of Liquids", Oxford University Press (1989)] Appendix G.5 (p. 349) </ref>. The function '''ran()''' calls a  [[Random_numbers | randon number generator]]: | ||
| <small><pre> | <small><pre> | ||
| !    The following is taken from Allen & Tildesley, p. 349 | !    The following is taken from Allen & Tildesley, p. 349 | ||
| Line 41: | Line 40: | ||
| ==References== | ==References== | ||
| <references/> | |||
| ==External links== | |||
| *[http://mathworld.wolfram.com/SpherePointPicking.html Sphere Point Picking] from Wolfram MathWorld | |||
| {{Source}} | |||
| [[category: random numbers]] | [[category: random numbers]] | ||
| [[category: computer simulation techniques]] | [[category: computer simulation techniques]] | ||
Latest revision as of 13:55, 21 October 2010
The ability to generate a randomly orientated vector is very useful in Monte Carlo simulations of anisotropic models or molecular systems.
Marsaglia algorithm[edit]
This is the algorithm proposed by George Marsaglia [1]
- Independently generate V1 and V2, taken from a uniform distribution on (-1,1) such that
- The random vector is then (Eq. 4 in [1] ):
Fortran 90 implementation[edit]
This Fortran 90 implementation is adapted from Refs. [2] and [3]. The function ran() calls a 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[edit]
- ↑ 1.0 1.1 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", Second Edition (2002) Algorithm 42 (p. 578)
- ↑ M. P. Allen and D. J. Tildesley "Computer Simulation of Liquids", Oxford University Press (1989) Appendix G.5 (p. 349)
External links[edit]
- Sphere Point Picking from Wolfram MathWorld
|   | This page contains computer source code. If you intend to compile and use this code you must check for yourself the validity of the code. Please read the SklogWiki disclaimer. |