I have an large array of elements that I call RelDist (In which dimensionally, is a unit of distance) in a simulated volume. I am attempting to determine the distribution for the "number of values per unit volume" which is also number density. It should be similar to this diagram:

I am aware that the axis is scaled log base 10, the plot of the set should definitely drop off.

Mathematically, I set it up as two equivalent equations:

where N is the number of elements in the array being differentiated in respect to the natural log of the distances. It can also be equivalently re-written in the form of a regular derivative by introducing another factor of r.

Equivalently,

So for ever increasing r, I want to count the change in N of elements per logarithmic bin of r.

As of now, I have trouble setting up the frequency counting in the histogram while accommodating the volume along side it.

Attempt 1

This is using the dN/dlnr/volume equations

def n(dist, numbins): logdist= np.log(dist) hist, r_array = np.histogram(logdist, numbins) dlogR = r_array[1]-r_array[0] x_array = r_array[1:] - dlogR/2 ## I am condifent the above part of this code is correct. ## The succeeding portion does not work. dR = r_array[1:] - r_array[0:numbins] dN_dlogR = hist * x_array/dR volume = 4*np.pi*dist*dist*dist ## The included volume is incorrect return [x_array, dN_dlogR/volume]

Plotting this does not even properly show a distribution like the first plot I posted above and it only works when I choose the bin number to be the same shape as my input array. The bun number should arbitrary, should it not?

Attempt 2

This is using the equivalent dN/dr/volume equation.

numbins = np.linspace(min(RelDist),max(RelDist), 100) hist, r_array = np.histogram(RelDist, numbins) volume = 4*np.float(1000**2) dR = r_array[1]-r_array[0] x_array = r_array[1:] - dR/2 y = hist/dR

A little bit easier, but without including the volume term, I get a sort of histogram distribution, which is at least a start.

With this attempt, how would include the volume term with the array?

Example

Start at a distance R value of something like 10, counts the change in number in respect to R, then increasing to a distance value R of 20, counts the change, increase to value of 30, counts the change, and so on so forth.

Here is a txt file of my array if you are interested in re-creating it

https://www.dropbox.com/s/g40gp88k2p6pp6y/RelDist.txt?dl=0