I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 0.20
sub units 0.75
+
0

Median

Returns the median of the given population.
Controller: CodeCogs

Dependents

Info

Interface

C++

Median

 
template<class T> doublemedianintn
T*data )[inline]
The median is the number in the middle of a set of numbers; that is, half the numbers have values that are greater than the median, and half have values that are less. If there is an even number of numbers in the set, then it calculates the average of the two numbers in the middle. In order to calculate the median, this algorithm uses the Smallest function.

Example:

#include <codecogs/statistics/moments/median.h>
#include <iostream>
int main()
{
  double
  x[6] = {0.2, 1.24, 0.5, 2.54, 2.3, 0.3},
  y[6] = {1, 2, 3.2, 4, 5},
  medx = Stats::Moments::median<double>(6, x),
  medy = Stats::Moments::median<double>(5, y);
  std::cout << "The median of the x array is: " << medx << std::endl;
  std::cout << "The median of the y array is: " << medy << std::endl;
  return 0;
}

Output:

The median of the x array is: 0.87
The median of the y array is: 3.2

References:

SUBSET, a library of C++ combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html

Parameters

nthe size of the population
datathe actual population given as an array

Returns

the median of the population

Authors

Anca Filibiu (August 2005)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.