HTML automatically generated with rman
Table of Contents
median, init_median, finis_median - compute the median of a distribution
#include <moment.h>
real median(int n, real *x);void init_median(int size);void finis_median(void);real
median_torben(int n, real *x, real xmin, real xmax);
median computes
the median value of a set of real values. Is uses an internal indexed sorting
routine sortptr(real *x, int *ix, int n) where the index array is automatically
allocated and resized depending on the need. Since NEMO does not have automated
garbage collection, finis_median() should be called to free up memory associated
with the sorting procedure (the index array).
This routine is very efficient
if many medians are needed, however depending on your array (size), the
sorting routine (a shell sort) may not be optimal for you.
The following
code computes the median
real med, x[100];
int n=100;
init_median(n);
med = median(n,x);
finis_median();
moment(3NEMO)
Peter Teuben
~/src/kernel/misc median.c
20-jun-01 written PJT
10-jun-05 man page written PJT
6-aug-2012 added Torben method PJT
Table of Contents