From 9aadcbf8a7188d11c7adbf583b9fbaea4ce25a5c Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Tue, 24 Mar 2020 01:41:45 +0000 Subject: [PATCH] ex-1: add median test --- ex-1/main.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ex-1/main.c b/ex-1/main.c index c45396e..b9e3b94 100644 --- a/ex-1/main.c +++ b/ex-1/main.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "landau.h" #include "tests.h" @@ -140,13 +141,29 @@ int main(int argc, char** argv) { // print the results fprintf(stderr, "\n\n# FWHM comparison\n"); double fwhm_e = numeric_fwhm(min, max, mode_e); + fprintf(stderr, "\n# Results\n"); fprintf(stderr, "expected FWHM: %.7f\n", fwhm_e); fprintf(stderr, "observed FWHM: %.3f\n", fwhm_o); - // print the counts - // gsl_histogram_fprintf(stdout, hist, "%g", "%g"); + /* Median comparison + * + * Compute the median of the sample + * and compare it with QDF(1/2). + */ + fprintf(stderr, "\n\n# Median comparison\n"); + double med_e = landau_qdf(0.5); + double med_o = gsl_stats_median_from_sorted_data( + sample, // sorted data + 1, // array stride + samples); // number of elements + + // print the results + fprintf(stderr, "\n# Results\n"); + fprintf(stderr, "expected median: %.7f\n", med_e); + fprintf(stderr, "observed median: %.7f\n", med_o); + // clean up and exit gsl_histogram_free(hist);