Logarithmic Size Bins

I have a file containing data for a large number of particles (approx 10^8), that need to be put into both size and density bins - similar to a 2D histogram.

The density variations is linear so I can just split this easily into 10(ish) bins, but The sizes vary on a log scale (somewhere around the nanometer to millimetre range) and the upper and lower bounds can drastically change between datasets and hence need to be calculated instead of hard-coded.

I am skimming through the file to find the minimum and maximum radius present so that I can define the upper and lower bounds of my histogram (which works fine). My next step is to take these values to create the upper and lower bounds, butI have no idea how to do this!

Can anybody help or already know of a method??
Thanks in Advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <cmath>
#include <iomanip>

int main()
{
    const double min_value = 3.0e-10 ;
    const double max_value = 5.0e+10 ;

    const double min_log = std::log(min_value) ;
    const double max_log = std::log(max_value) ;

    const int num_intervals = 10 ;
    const double log_increment = ( max_log - min_log ) / num_intervals ;

    double value = min_value ;
    double log_value = min_log ;
    std::cout << std::scientific << std::setprecision(5) << "intervals\n--------\n" ;
    for( int i = 0 ; i < num_intervals ; ++i )
    {
        std::cout << std::setw(2) << i+1 << ". " << value  << " - " ;
        log_value += log_increment ;
        value = std::exp(log_value) ;
        std::cout << value << '\n' ;
    }
}

clang++ -std=c++11 -stdlib=libc++ -O2 -Wall -Wextra -pedantic-errors main.cpp -lsupc++ && ./a.out
intervals
--------
 1. 3.00000e-10 - 3.15723e-08
 2. 3.15723e-08 - 3.32270e-06
 3. 3.32270e-06 - 3.49684e-04
 4. 3.49684e-04 - 3.68011e-02
 5. 3.68011e-02 - 3.87298e+00
 6. 3.87298e+00 - 4.07597e+02
 7. 4.07597e+02 - 4.28959e+04
 8. 4.28959e+04 - 4.51440e+06
 9. 4.51440e+06 - 4.75100e+08
10. 4.75100e+08 - 5.00000e+10

http://coliru.stacked-crooked.com/a/38351ba6805e76de
Thanks alot!!
Topic archived. No new replies allowed.