21#include "marley/InterpolatingFunction.hh"
26 constexpr size_t DEFAULT_N_CHEBYSHEV = 64u;
35 double x_min,
double x_max,
size_t N = 0 );
39 inline double evaluate(
double x )
const override {
43 for (
size_t j = 0; j <=
N_; ++j ) {
45 double x_j =
Xs_.at( j );
46 double f_j =
Fs_.at( j );
50 if ( x_j == x )
return f_j;
52 double temp = w_j / ( x - x_j );
53 if ( j == 0 || j ==
N_ ) temp /= 2.;
58 double px = numer / denom;
64 inline double integral()
const {
return integral_; };
66 inline const std::vector<double>& chebyshev_coeffs()
const
69 inline const std::vector<double>& Fs()
const
72 inline const std::vector<double>& Xs()
const
75 inline int N()
const {
return N_; }
79 inline double x_min()
const {
return x_min_; }
80 inline double x_max()
const {
return x_max_; }
88 static constexpr size_t N_MAX_ = 65536u;
97 std::vector<double>
Xs_;
106 std::vector<double> wsave_;
107 std::vector<int> ifac_;
115 double x = std::cos(
static_cast<double>(marley_utils::pi * j) /
N_ );
121 void compute_integral();
double integral_
Approximate integral of the function on [x_min_, x_max_].
static constexpr size_t N_MAX_
Maximum allowed value of the grid size parameter.
size_t N_
Grid size parameter (N + 1 total points)
ChebyshevInterpolatingFunction(const std::function< double(double)> &func, double x_min, double x_max, size_t N=0)
ChebyshevInterpolatingFunction()
Default constructor used by cdf()
double chebyshev_point(size_t j) const
For a given N, returns the x position of the jth Chebyshev point (of the second kind)
double evaluate(double x) const override
Approximates the represented function using the barycentric formula.
std::vector< double > Xs_
Chebyshev points at which the function was evaluated.
std::vector< double > chebyshev_coeffs_
Coefficients of the Chebyshev expansion of this function.
std::vector< double > Fs_
Function values at the grid points.
double x_max_
Upper bound of the interpolation range.
double x_min_
Lower bound of the interpolation range.