The functions for allocating memory to a histogram follow the style of
malloc
and free
. In addition they also perform their own
error checking. If there is insufficient memory available to allocate a
histogram then the functions call the error handler (with an error
number of GSL_ENOMEM
) in addition to returning a null pointer.
Thus if you use the library error handler to abort your program then it
isn't necessary to check every histogram alloc
.
gsl_histogram
struct. If
insufficient memory is available a null pointer is returned and the
error handler is invoked with an error code of GSL_ENOMEM
. The
bins and ranges are not initialized, and should be prepared using one of
the range-setting functions below in order to make the histogram ready
for use.
range
array should contain the
desired bin limits. The ranges can be arbitrary, subject to the
restriction that they are monotonically increasing.
The following example shows how to create a histogram with logarithmic bins with ranges [1,10), [10,100) and [100,1000).
gsl_histogram * h = gsl_histogram_alloc (3); /* bin[0] covers the range 1 <= x < 10 */ /* bin[1] covers the range 10 <= x < 100 */ /* bin[2] covers the range 100 <= x < 1000 */ double range[4] = { 1.0, 10.0, 100.0, 1000.0 }; gsl_histogram_set_ranges (h, range, 4);
Note that the size of the range array should be defined to be one element bigger than the number of bins. The additional element is required for the upper value of the final bin.
where @math{d} is the bin spacing, @math{d = (xmax-xmin)/n}.