-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoisson.c
56 lines (43 loc) · 1.72 KB
/
poisson.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*******************************************************************/
/* poisson.c ->void POISSON(in,out) */
/* Jing M. Chen, [email protected] */
/* Sylvain G. Leblanc [email protected] */
/*******************************************************************/
/* Subroutine that calculates the poisson distribution for random */
/* distribution of trees */
/* Latest update February 4, 1997 */
/*******************************************************************/
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
# include "data.h"
void POISSON(in_p,out_p)
struct PARAMETER in_p;
struct RESULT *out_p;
{
double exp();
double M; /* Mean value of the distribution */
int ai,ak; /* dummy variables */
double PNN=0; /* initial value in computaion of *PX */
double PX_tot=0; /* sum of all *PX */
M = in_p.D/in_p.n;
for (ak=0;ak<NN;ak++)
{
PNN = exp(-M);
for (ai=1;ai<=ak;ai++)
{
PNN =PNN*M/(ai*1.);
}
out_p->Px[ak] = PNN;
PX_tot = PX_tot + out_p->Px[ak];
}
if (PX_tot <0.95)
{
printf("\n Possible error in Poisson distribution:");
printf(" sum of all tree distribution probabilities is less ");
printf("than 0.95 (sum=%8.5f) \n",PX_tot);
}
for (ak=0;ak<NN;ak++) out_p->Px[ak] = out_p->Px[ak]/ PX_tot;
/* in case IMAX is not large enough so that PX_tot equals unity,
a normalisation is done for PX */
}