Environmental Engineering Reference
In-Depth Information
float z_calc(void)
//this is a procedure for getting a
value from a normal distribution
{
#define comp 8000
#define pi 3.141592654
float prob,step,LastP;
float incre,cumprob,z_val;
double RNo;
RNo = (double)rand()/(double)RAND_MAX;
z_val = 0; cumprob = 0;
incre = 8/(float)comp;
step = -4;
while (step <=4)
{
step = step + incre;
prob = (1/sqrt(2*pi))*exp(-(step*step)/2);
LastP = cumprob;
cumprob = cumprob + (prob*incre);
if (RNo > LastP && RNo < cumprob)
{z_val = (step - incre) + incre*((RNo-LastP)/
(cumprob-LastP));
step = 4;}
}
return z_val;
} //Zcalc
//**********************************************************
float round(float PrdF)
//this is a procedure for rounding a
number
{
float Prdn,diff;
int low,high;
low = (int)PrdF;
high = (int)PrdF+1;
diff = PrdF-low;
if (diff<0.5) Prdn = (float)low;
else Prdn = (float)high;
return Prdn;
} //round
//**********************************************************
Search WWH ::




Custom Search