slarnv.f.html

来自「famous linear algebra library (LAPACK) p」· HTML 代码 · 共 138 行

HTML
138
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>slarnv.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="SLARNV.1"></a><a href="slarnv.f.html#SLARNV.1">SLARNV</a>( IDIST, ISEED, N, X )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK auxiliary routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      INTEGER            IDIST, N
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      INTEGER            ISEED( 4 )
      REAL               X( * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="SLARNV.18"></a><a href="slarnv.f.html#SLARNV.1">SLARNV</a> returns a vector of n random real numbers from a uniform or
</span><span class="comment">*</span><span class="comment">  normal distribution.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  IDIST   (input) INTEGER
</span><span class="comment">*</span><span class="comment">          Specifies the distribution of the random numbers:
</span><span class="comment">*</span><span class="comment">          = 1:  uniform (0,1)
</span><span class="comment">*</span><span class="comment">          = 2:  uniform (-1,1)
</span><span class="comment">*</span><span class="comment">          = 3:  normal (0,1)
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  ISEED   (input/output) INTEGER array, dimension (4)
</span><span class="comment">*</span><span class="comment">          On entry, the seed of the random number generator; the array
</span><span class="comment">*</span><span class="comment">          elements must be between 0 and 4095, and ISEED(4) must be
</span><span class="comment">*</span><span class="comment">          odd.
</span><span class="comment">*</span><span class="comment">          On exit, the seed is updated.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of random numbers to be generated.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  X       (output) REAL array, dimension (N)
</span><span class="comment">*</span><span class="comment">          The generated random numbers.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Further Details
</span><span class="comment">*</span><span class="comment">  ===============
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  This routine calls the auxiliary routine <a name="SLARUV.45"></a><a href="slaruv.f.html#SLARUV.1">SLARUV</a> to generate random
</span><span class="comment">*</span><span class="comment">  real numbers from a uniform (0,1) distribution, in batches of up to
</span><span class="comment">*</span><span class="comment">  128 using vectorisable code. The Box-Muller method is used to
</span><span class="comment">*</span><span class="comment">  transform numbers from a uniform to a normal distribution.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      REAL               ONE, TWO
      PARAMETER          ( ONE = 1.0E+0, TWO = 2.0E+0 )
      INTEGER            LV
      PARAMETER          ( LV = 128 )
      REAL               TWOPI
      PARAMETER          ( TWOPI = 6.2831853071795864769252867663E+0 )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      INTEGER            I, IL, IL2, IV
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Arrays ..
</span>      REAL               U( LV )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          COS, LOG, MIN, SQRT
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           <a name="SLARUV.70"></a><a href="slaruv.f.html#SLARUV.1">SLARUV</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span>      DO 40 IV = 1, N, LV / 2
         IL = MIN( LV / 2, N-IV+1 )
         IF( IDIST.EQ.3 ) THEN
            IL2 = 2*IL
         ELSE
            IL2 = IL
         END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Call <a name="SLARUV.82"></a><a href="slaruv.f.html#SLARUV.1">SLARUV</a> to generate IL2 numbers from a uniform (0,1)
</span><span class="comment">*</span><span class="comment">        distribution (IL2 &lt;= LV)
</span><span class="comment">*</span><span class="comment">
</span>         CALL <a name="SLARUV.85"></a><a href="slaruv.f.html#SLARUV.1">SLARUV</a>( ISEED, IL2, U )
<span class="comment">*</span><span class="comment">
</span>         IF( IDIST.EQ.1 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Copy generated numbers
</span><span class="comment">*</span><span class="comment">
</span>            DO 10 I = 1, IL
               X( IV+I-1 ) = U( I )
   10       CONTINUE
         ELSE IF( IDIST.EQ.2 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Convert generated numbers to uniform (-1,1) distribution
</span><span class="comment">*</span><span class="comment">
</span>            DO 20 I = 1, IL
               X( IV+I-1 ) = TWO*U( I ) - ONE
   20       CONTINUE
         ELSE IF( IDIST.EQ.3 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Convert generated numbers to normal (0,1) distribution
</span><span class="comment">*</span><span class="comment">
</span>            DO 30 I = 1, IL
               X( IV+I-1 ) = SQRT( -TWO*LOG( U( 2*I-1 ) ) )*
     $                       COS( TWOPI*U( 2*I ) )
   30       CONTINUE
         END IF
   40 CONTINUE
      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="SLARNV.113"></a><a href="slarnv.f.html#SLARNV.1">SLARNV</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?