Télécharger dlarnv.eso

Retour à la liste

Numérotation des lignes :

dlarnv
  1. C DLARNV SOURCE BP208322 18/07/10 21:15:15 9872
  2. *> \brief \b DLARNV returns a vector of random numbers from a uniform or normal distribution.
  3. *
  4. * =========== DOCUMENTATION ===========
  5. *
  6. * Online html documentation available at
  7. * http://www.netlib.org/lapack/explore-html/
  8. *
  9. *> \htmlonly
  10. *> Download DLARNV + dependencies
  11. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlarnv.f">
  12. *> [TGZ]</a>
  13. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlarnv.f">
  14. *> [ZIP]</a>
  15. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlarnv.f">
  16. *> [TXT]</a>
  17. *> \endhtmlonly
  18. *
  19. * Definition:
  20. * ===========
  21. *
  22. * SUBROUTINE DLARNV( IDIST, ISEED, N, X )
  23. *
  24. * .. Scalar Arguments ..
  25. * INTEGER IDIST, N
  26. * ..
  27. * .. Array Arguments ..
  28. * INTEGER ISEED( 4 )
  29. * REAL*8 X( * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> DLARNV returns a vector of n random real numbers from a uniform or
  39. *> normal distribution.
  40. *> \endverbatim
  41. *
  42. * Arguments:
  43. * ==========
  44. *
  45. *> \param[in] IDIST
  46. *> \verbatim
  47. *> IDIST is INTEGER
  48. *> Specifies the distribution of the random numbers:
  49. *> = 1: uniform (0,1)
  50. *> = 2: uniform (-1,1)
  51. *> = 3: normal (0,1)
  52. *> \endverbatim
  53. *>
  54. *> \param[in,out] ISEED
  55. *> \verbatim
  56. *> ISEED is INTEGER array, dimension (4)
  57. *> On entry, the seed of the random number generator; the array
  58. *> elements must be between 0 and 4095, and ISEED(4) must be
  59. *> odd.
  60. *> On exit, the seed is updated.
  61. *> \endverbatim
  62. *>
  63. *> \param[in] N
  64. *> \verbatim
  65. *> N is INTEGER
  66. *> The number of random numbers to be generated.
  67. *> \endverbatim
  68. *>
  69. *> \param[out] X
  70. *> \verbatim
  71. *> X is DOUBLE PRECISION array, dimension (N)
  72. *> The generated random numbers.
  73. *> \endverbatim
  74. *
  75. * Authors:
  76. * ========
  77. *
  78. *> \author Univ. of Tennessee
  79. *> \author Univ. of California Berkeley
  80. *> \author Univ. of Colorado Denver
  81. *> \author NAG Ltd.
  82. *
  83. *> \date December 2016
  84. *
  85. *> \ingroup OTHERauxiliary
  86. *
  87. *> \par Further Details:
  88. * =====================
  89. *>
  90. *> \verbatim
  91. *>
  92. *> This routine calls the auxiliary routine DLARUV to generate random
  93. *> real numbers from a uniform (0,1) distribution, in batches of up to
  94. *> 128 using vectorisable code. The Box-Muller method is used to
  95. *> transform numbers from a uniform to a normal distribution.
  96. *> \endverbatim
  97. *>
  98. * =====================================================================
  99. SUBROUTINE DLARNV( IDIST, ISEED, N, X )
  100. *
  101. * -- LAPACK auxiliary routine (version 3.7.0) --
  102. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  103. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  104. * December 2016
  105. *
  106. * .. Scalar Arguments ..
  107. INTEGER IDIST, N
  108. * ..
  109. * .. Array Arguments ..
  110. INTEGER ISEED( 4 )
  111. REAL*8 X( * )
  112. * ..
  113. *
  114. * =====================================================================
  115. *
  116. * .. Parameters ..
  117. REAL*8 ONE, TWO
  118. PARAMETER ( ONE = 1.0D+0, TWO = 2.0D+0 )
  119. INTEGER LV
  120. PARAMETER ( LV = 128 )
  121. REAL*8 TWOPI
  122. PARAMETER ( TWOPI = 6.2831853071795864769252867663D+0 )
  123. * ..
  124. * .. Local Scalars ..
  125. INTEGER I, IL, IL2, IV
  126. * ..
  127. * .. Local Arrays ..
  128. REAL*8 U( LV )
  129. * ..
  130. ** .. Intrinsic Functions ..
  131. * INTRINSIC COS, LOG, MIN, SQRT
  132. ** ..
  133. ** .. External Subroutines ..
  134. * EXTERNAL DLARUV
  135. ** ..
  136. ** .. Executable Statements ..
  137. *
  138. DO 40 IV = 1, N, LV / 2
  139. IL = MIN( LV / 2, N-IV+1 )
  140. IF( IDIST.EQ.3 ) THEN
  141. IL2 = 2*IL
  142. ELSE
  143. IL2 = IL
  144. END IF
  145. *
  146. * Call DLARUV to generate IL2 numbers from a uniform (0,1)
  147. * distribution (IL2 <= LV)
  148. *
  149. CALL DLARUV( ISEED, IL2, U )
  150. *
  151. IF( IDIST.EQ.1 ) THEN
  152. *
  153. * Copy generated numbers
  154. *
  155. DO 10 I = 1, IL
  156. X( IV+I-1 ) = U( I )
  157. 10 CONTINUE
  158. ELSE IF( IDIST.EQ.2 ) THEN
  159. *
  160. * Convert generated numbers to uniform (-1,1) distribution
  161. *
  162. DO 20 I = 1, IL
  163. X( IV+I-1 ) = TWO*U( I ) - ONE
  164. 20 CONTINUE
  165. ELSE IF( IDIST.EQ.3 ) THEN
  166. *
  167. * Convert generated numbers to normal (0,1) distribution
  168. *
  169. DO 30 I = 1, IL
  170. X( IV+I-1 ) = SQRT( -TWO*LOG( U( 2*I-1 ) ) )*
  171. $ COS( TWOPI*U( 2*I ) )
  172. 30 CONTINUE
  173. END IF
  174. 40 CONTINUE
  175. RETURN
  176. *
  177. * End of DLARNV
  178. *
  179. END
  180.  
  181.  
  182.  

© Cast3M 2003 - Tous droits réservés.
Mentions légales