-
Notifications
You must be signed in to change notification settings - Fork 4
/
c_normalpdf.c
47 lines (38 loc) · 989 Bytes
/
c_normalpdf.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
#include <math.h>
#include <stdio.h>
double standard_normalpdf(double x) {
double p;
double pi = M_PI;
p = (exp((-0.5)*x*x))/(sqrt(2.0*pi));
return p;
}
double normalpdf(double x, double mu, double sigma) {
double p;
p = standard_normalpdf((x-mu)/sigma)/sigma;
return p;
}
double standard_normalcdf(double x) {
double p;
p = (1.0 + erf(x/sqrt(2.0)))/2.0;
return p;
}
double normalcdf(double x, double mu, double sigma) {
double p;
p = standard_normalcdf((x-mu)/sigma);;
return p;
}
int main() {
double x;
for (x=-4.0; x <= 4.001; x+=0.1) {
printf("%0.2f %1.8f\n",x,standard_normalpdf(x));
}
for (x=-4.0; x <= 4.001; x+=0.1) {
printf("%0.2f %1.8f\n",x,normalpdf(x,-1.0,0.6));
}
for (x=-4.0; x <= 4.001; x+=0.1) {
printf("%0.2f %1.8f\n",x,standard_normalcdf(x));
}
for (x=-4.0; x <= 4.001; x+=0.1) {
printf("%0.2f %1.8f\n",x,normalcdf(x,1.0,0.25));
}
}