moyal.c: fix some typos and add it to the makefile
This commit is contained in:
parent
1833ab0613
commit
9b4fa56b49
16
ex-1/moyal.c
16
ex-1/moyal.c
@ -3,14 +3,18 @@
|
||||
* PDF, CDF and QDF functions.
|
||||
*/
|
||||
|
||||
#include <gsl/gsl_cdf.h>
|
||||
#include <gsl/gsl_sf.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/* This is a wrapper needed by `moyal_cdf` and
|
||||
/* The Moyal PDF.
|
||||
*
|
||||
* This is a wrapper needed by `moyal_cdf` and
|
||||
* other optimisation functions because the GSL
|
||||
* routines expect a function with parameters.
|
||||
*/
|
||||
double moyal_pdf(double x, void* params) {
|
||||
double moyal_pdf(double x, double* params) {
|
||||
double mu = params[0];
|
||||
double sigma = params[1];
|
||||
double z = (x - mu)/sigma;
|
||||
@ -20,20 +24,20 @@ double moyal_pdf(double x, void* params) {
|
||||
|
||||
/* The cumulative function of the Moyal distribution.
|
||||
*/
|
||||
double moyal_cdf(double x, void* params) {
|
||||
double moyal_cdf(double x, double* params) {
|
||||
double mu = params[0];
|
||||
double sigma = params[1];
|
||||
double z = (x - mu)/sigma;
|
||||
return 2*(1 - gsl_cdf_gaussian_P(exp(-x/2)));
|
||||
return 2 * (1 - gsl_cdf_gaussian_P(exp(-z/2), 1));
|
||||
}
|
||||
|
||||
|
||||
/* The quantile function (inverse CDF) of the Moyal
|
||||
* distribution.
|
||||
*/
|
||||
double moyal_qdf(double p0, void* params) {
|
||||
double moyal_qdf(double p0, double* params) {
|
||||
double mu = params[0];
|
||||
double sigma = params[1];
|
||||
double z = -2*log(gsl_cdf_gaussian_Pinv(1 - p/2));
|
||||
double z = -2 * log(gsl_cdf_gaussian_Pinv(1 - p0/2, 1));
|
||||
return z*sigma + mu;
|
||||
}
|
||||
|
2
makefile
2
makefile
@ -7,7 +7,7 @@ CCOMPILE = \
|
||||
$(CC) $(CFLAGS) $^ -o $@
|
||||
|
||||
ex-1: ex-1/bin/main ex-1/bin/pdf
|
||||
ex-1/bin/main: ex-1/main.c ex-1/landau.c ex-1/tests.c ex-1/bootstrap.c
|
||||
ex-1/bin/main: ex-1/main.c ex-1/landau.c ex-1/tests.c ex-1/bootstrap.c ex-1/moyal.c
|
||||
$(CCOMPILE)
|
||||
ex-1/bin/pdf: ex-1/pdf.c
|
||||
$(CCOMPILE)
|
||||
|
Loading…
Reference in New Issue
Block a user