Name:陈启武 Student number:2014200557 Profession:Microelectronics
Task1:Generate random variates for Gaussian distriubution and draw the corresponding PDFs
The principal:
In probability theory, the normal (or Gaussian) distribution is a very commonly occurring continuous probability distribution. The probability density function of the normal distribution is
The parameter in this definition is the mean or expectation of the distribution (and also its median and mode). The parameter is its standard deviation; its variance is therefore . A random variable with a Gaussian distribution is said to be normally distributed and is called a normal deviate.
b) The method of generating random numbers is to use the 搑and()?function to generate a random number in C++ program firstly, then the generated random number is mapped to the required range.In the text,I generated 10,000 random numbers followed by uniform distribution between the interval [-10,10].
c) We can use the generated random numbers to calculate density function values,these values are the required random numbers for normal distributon. In the test,I defined 搉ormal()?function to generate 10000 idensity function values which have been put in to a text called ?23?.
d) Finally,we must draw the corresponding PDFs to test and verify probability density function values with MATLAB. In the test,I I put the programmed datas into 500 groups and get the different histograms for normal(0,1),(0,4.26),(-2.5,1).
Here抯 the commands of matlab I have used in the test.u
m=load('F:\text\normal\123.txt')
hist(m,500)
Title(‘N(miu,sigma)’)
The C++ source program:
#include
#include
#include
#include
#include
using namespace std;
#define pi 3.1415926
//Generate a randon number followed by uniform distribution between the inteval [min,max]
template
T rand(T min, T max)
{
return min+(max-min)*rand()/(RAND_MAX+1.0);