Skip to content
Snippets Groups Projects
Commit e5200de3 authored by Aymeric Agon-Rambosson's avatar Aymeric Agon-Rambosson
Browse files

Ajout quantile.

parent d88f7ba8
Branches
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ moyenne
variance
histogramme
IC_moyenne
quantile
# Tous les fichiers objets
src/*.o
......
......@@ -33,7 +33,10 @@ HISTOGRAMME_OBJ = \
${COMMON_OBJ} \
src/histogram.o
BIN = total moyenne variance IC_moyenne histogramme
QUANTILE_OBJ = \
${COMMON_OBJ}
BIN = total moyenne variance IC_moyenne histogramme quantile
all: options ${BIN}
......@@ -69,6 +72,10 @@ histogramme: ${HISTOGRAMME_OBJ} src/main_histogramme.o
@echo LD -o $@
@${LD} -o $@ ${HISTOGRAMME_OBJ} src/main_histogramme.o ${LDFLAGS}
quantile: ${QUANTILE_OBJ} src/main_quantile.o
@echo LD -o $@
@${LD} -o $@ ${QUANTILE_OBJ} src/main_quantile.o ${LDFLAGS} ${GSLLIBS}
clean:
@echo Nettoyage
rm -f ${BIN} src/*.o
......
......@@ -19,7 +19,7 @@ par un blanc), interprètent ces nombres comme un échantillon d'une population
infinie et impriment une statistique particulière dans la sortie standard.
Ces programmes se veulent minimaux quant à leurs dépendances :
- libgsl-dev (pour IC_moyenne seulement, quantile de la loi de Student)
- libgsl-dev (pour IC_moyenne et quantile)
- libm (pour IC_moyenne seulement, calcul de la racine carrée)
- libc (pour tous les programmes)
......
/* statutils - Perform statistical operations on stdin data
*
* Copyright (C) 2022 Aymeric Agon-Rambosson
*
* This file is part of statutils.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* Written by Aymeric Agon-Rambosson */
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <gsl/gsl_sort.h>
#include <gsl/gsl_statistics.h>
#include "input.h"
static void
usage(void)
{
fprintf(stderr, "usage: quantile -p probabilité\n");
}
static void
run_double(const double proba)
{
double *array;
size_t array_size = get_stdin_double(&array);
double result;
gsl_sort(array, 1, array_size);
result = gsl_stats_quantile_from_sorted_data(array, 1, array_size,
proba);
printf("%lg\n", result);
}
int main(int argc, char *argv[])
{
int i;
double proba = -1;
for (i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "-h")) {
usage();
exit(0);
} else if (!strcmp(argv[i], "-p")) {
proba = strtod(argv[++i], NULL);
} else {
fprintf(stderr, "%s : Argument invalide\n", argv[i]);
exit(22);
}
}
if ((proba < 0) || (proba > 1)) {
fprintf(stderr,
"%lg : la fonction quantile est définie sur [0;1]\n",
proba);
usage();
exit(22);
}
run_double(proba);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment