This HTML automatically generated with rman for NEMO
Table of Contents

Name

median, init_median, finis_median - compute the median of a distribution

Synopsis


#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);

Description

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.

Examples

The following code computes the median
    real med, x[100];
    int  n=100;
    
    init_median(n);
    med = median(n,x);
    finis_median();
    

See Also

moment(3NEMO)

Author

Peter Teuben

Files


~/src/kernel/misc    median.c

Update History


20-jun-01    written     PJT
10-jun-05    man page written    PJT
6-aug-2012    added Torben method    PJT


Table of Contents