Creating a distribution with specific mean and variance in FORTRAN 90

Click For Summary

Discussion Overview

The discussion focuses on generating a normal distribution with a specified mean and variance using FORTRAN 90. Participants explore methods to achieve this, particularly in comparison to MATLAB's approach.

Discussion Character

  • Technical explanation, Exploratory, Debate/contested

Main Points Raised

  • One participant seeks assistance in creating a normal distribution with a mean of 0.5 and variance of 0.05 in FORTRAN 90, questioning if using RANDOM_NUMBER with a specific equation would yield similar results to their MATLAB implementation.
  • Another participant asserts that RANDOM_NUMBER cannot directly produce a normal distribution since it generates uniform random numbers, suggesting methods like the Box-Muller transform to convert uniform to normal distribution.
  • A third participant shares a link to C source code that implements the Box-Muller transform for generating normally distributed random numbers, indicating that the algorithm can be adapted for use in FORTRAN.

Areas of Agreement / Disagreement

Participants generally agree on the limitation of RANDOM_NUMBER for generating normal distributions and suggest alternative methods, but there is no consensus on the best approach to implement this in FORTRAN 90.

Contextual Notes

The discussion does not resolve the specific implementation details in FORTRAN 90, and assumptions about the participants' familiarity with the Box-Muller transform and its adaptation to different programming languages remain unaddressed.

Who May Find This Useful

Readers interested in statistical programming, specifically those working with FORTRAN 90 and seeking to generate normal distributions, may find this discussion relevant.

sue132
Messages
14
Reaction score
0
Hi,

I'm trying to create a normal distribution with mean 0.5 and variance 0.05. I tried it initially with MATLAB, for which I used
Code:
newdist=0.5+(randn(1,1000)*sqrt(0.05));

Could you please help me in doing this in FORTRAN 90? Would generating a sequence using RANDOM_NUMBER and using the above equation give me similar results?

Thank you.

(P.S. : The LINUX OS on my system needs to be replaced, and I'm writing some more code before I can run them on another system. It would be great to have your help in the meanwhile, so I could check everything together. Thanks again)
 
Technology news on Phys.org


You can't do it directly with random_number, which has a uniform distribution. There are different ways to produce a normal distribution from a uniform distribution, such as the Box-Muller transform.
 
Hi sue132! :smile:

http://www.ohio.edu/people/just/Escalate/source/random.ccsome C source code for nrandom that generates normally distributed random numbers (based on the Box-muller transform).

The algorithm is easy to port to any computer language.
It comes from Numerical Recipes in C, for which there is also a FORTRAN version.
 


Thank you for the replies
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
6K
  • · Replies 8 ·
Replies
8
Views
5K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K