mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
logRadProfIntegrator.hpp
1
2#include <gsl/gsl_integration.h>
3#include <gsl/gsl_errno.h>
4
5#include "constants.hpp"
6#include "logInterpolator.hpp"
7
8namespace mx
9{
10namespace math
11{
12
13template <typename interpT>
14typename interpT::realT logRadProfIntegrationF( typename interpT::realT x, void *params )
15{
17
18 return ( *lI )(x)*x;
19}
20
21/// Integrate a numerical radial profile using logarithmic interpolation
22/** Useful for steep power-law like functions like power-spectra
23 *
24 * \returns the value of the integral over the limits
25 */
26template <typename interpT>
27typename interpT::realT
28logRadProfIntegrator( const std::vector<typename interpT::realT>
29 &x, ///< [in] the x values of the function. Must be positive definite (can not contain 0).
30 const std::vector<typename interpT::realT>
31 &y, ///< [in] the y values of the function. Must be positive definite (can not contain 0).
32 typename interpT::realT x0, ///< [in] [optional] the lower limit of integration
33 typename interpT::realT xf ///< [in] [optional] the uper limit of integration
34)
35{
36 typedef typename interpT::realT realT;
37
39
40 logInterp.setup( x, y );
41 gsl_function func;
42 func.function = &logRadProfIntegrationF<interpT>;
43 func.params = &logInterp;
44
45 realT result;
46 realT abserr;
47 size_t neval;
48
51
52 int rv = gsl_integration_qag( &func, x0, xf, 1e-3, 1e-3, 1e6, 6, w, &result, &abserr );
53
55
57
58 return result;
59}
60
61/// Integrate a numerical radial profile using logarithmic interpolation
62/** Useful for steep power-law like functions like power-spectra
63 *
64 * \returns the value of the integral over the entire domain given by \p x
65 */
66template <typename interpT>
67typename interpT::realT
68logRadProfIntegrator( const std::vector<typename interpT::realT>
69 &x, ///< [in] the x values of the function. Must be positive definite (can not contain 0).
70 const std::vector<typename interpT::realT>
71 &y ///< [in] the y values of the function. Must be positive definite (can not contain 0).
72)
73{
74 return logRadProfIntegrator<interpT>( x, y, x[0], x.back() );
75}
76
77} // namespace math
78} // namespace mx
Interpolate a function in log space.
void setup(const std::vector< realT > &x, const std::vector< realT > &y)
Convert the inputs to their log10 values, and construct the interpolator.
constexpr floatT six_fifths()
Return 6/5 in the specified precision.
Interpolation in log space.
The mxlib c++ namespace.
Definition mxError.hpp:106