Formula for median of a set (sorted)

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
shadowboy13
Messages
20
Reaction score
0
Now i think i derived this correctly, but I'm not sure if it's correct, can anyone give me a confirmation?

##n-1/2=x##

Where ##x## is the result of subtracting 1 from the observations and then dividing by 2.

Then ##x+1=Median##

Thank you :)

Edit: Oops, this is the handicapped version of the better formula... figures
 
Physics news on Phys.org
If you're writing a method that returns the median of a sorted set of n numerical observations, I'm assuming they are all sorted in an array of size n. If so, you have to check whether the size of the array is an even or odd number. If even, return the arithmetic mean of the middle two observations; if odd, return the middle observation. This might look like:

public double getMedian( data [] list )
{
if( list.length % 2 == 0 )
return ( list[ list.length / 2 ] + list[ ( list.length / 2 ) - 1 ] ) / 2.0;
else
return list[ list.length / 2 ];
}