|
我有用Fortran 编的,你改为matlab 吧
!! Function to Return a Gaussian Noise with Mean u and Variance g
Real Function GaussianNoise(u,g)
USE PORTLIB
Real u,g
Integer n
Real b
n=12 ; b=0.0
do i=1,n
b=b+RANDOM(0)
enddo
GaussianNoise = u+g*(b-n/2)
Return
End Function GaussianNoise
!! Function to Return a Gaussian Noise (0,1) based on Box-Muller Method ----
Real Function Gasdev()
USE PORTLIB
USE MSFLIB
Real x1, x2, x3, f1
if( jf_set == 0 ) then
10 x1 = 2.0 * RANDOM(0) - 1.0
x2 = 2.0 * RANDOM(0) - 1.0
x3 = x1 * x1 + x2 * x2
if( x3 > 1.0 .OR. x3 == 0.0 ) goto 10
f1 = SQRT( -2.0 * log( x3 ) / x3 )
noise_set = x1 * f1
jf_set = 1
GASDEV = x2 * f1
else
jf_set = 0
GASDEV = noise_set
endif
Return
End Function Gasdev |
评分
-
1
查看全部评分
-
|