Re: Add Noise
beliavsky_at_aol.com
Date: 03/18/04
- Next message: Clive Page: "Re: dbase reader"
- Previous message: Tim Prince: "Re: g77, cygwin, CALL System('cls')"
- In reply to: Filippos Louis: "Add Noise"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 18 Mar 2004 14:33:24 -0800
"Filippos Louis" <flouis@geol.uoa.gr> wrote in message news:<c3c3cm$33i$1@nic.grnet.gr>...
> Hi all
> Does anyone know of a Fortran routine to add noise to data on a vector?
> (Gaussian or Random)!
> Thank you in advance
>
> FLouis
Here is a Fortran 90/95 function with driver to simulate Gaussian
variates using the Box-Muller algoritm.
module box_muller
implicit none
public :: normal_bm
contains
function normal_bm() result(zz)
! generate a random normal deviate using the Box-Muller method
real :: zz
real :: dist,xx(2)
real, parameter :: two = 2.0, minus_two = -2.0
do
call random_number(xx)
xx = two*xx - 1.0
dist = xx(1)**2 + xx(2)**2
if (dist < 1.0) exit
end do
zz = xx(1)*sqrt(minus_two*log(dist)/dist)
end function normal_bm
end module box_muller
program xnormal_bm
use box_muller, only: normal_bm
implicit none
integer :: i
integer, parameter :: n = 1000000
real :: xx(n)
call random_seed()
do i=1,n
xx(i) = normal_bm()
end do
write (*,"(' moments:',100f8.4)") &
(/sum(xx),sum(xx**2),sum(xx**3),sum(xx**4)/) / n
end program xnormal_bm
With Compaq Visual Fortran 6.6 it produce the result
moments: 0.0010 0.9970 0.0037 2.9859
which looks good. Can anyone recommend a Fortran code to test the
quality of a vector of variates that are supposed to be IID normal?
Some sources for Fortran codes for random number generation are listed
at http://www.dmoz.org/Computers/Programming/Languages/Fortran/Source_Code/Statistics_and_Econometrics/
.
- Next message: Clive Page: "Re: dbase reader"
- Previous message: Tim Prince: "Re: g77, cygwin, CALL System('cls')"
- In reply to: Filippos Louis: "Add Noise"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|