Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <cstddef> 7 : 8 : /// \cond 9 : class DataVector; 10 : class Matrix; 11 : /// \endcond 12 : 13 : namespace intrp { 14 : /*! 15 : * \brief Computes the matrix for polynomial interpolation of a non-periodic 16 : * function known at the set of points \f$x_{source}\f$ to the set of points 17 : * \f$x_{target}\f$ 18 : * 19 : * \details The algorithm is from \cite Fornberg1998. The returned matrix 20 : * \f$M\f$ will have \f$n_{target}\f$ rows and \f$n_{source}\f$ columns so that 21 : * \f$f_{target} = M f_{source}\f$ 22 : * 23 : * \note The accuracy of the interpolation will depend upon the number and 24 : * distribution of the source points. It is strongly suggested that you 25 : * carefully investigate the accuracy for your use case. 26 : */ 27 : template <typename TargetDataType> 28 1 : Matrix fornberg_interpolation_matrix(const TargetDataType& x_target, 29 : const DataVector& x_source); 30 : 31 : /*! 32 : * \brief Computes the matrix for interpolating a periodic function known at the 33 : * set of \f$n\f$ equally spaced points on the periodic domain \f$[0, 2 \pi]\f$ 34 : * to the set of points \f$x_{target}\f$ 35 : * 36 : * \details The returned matrix \f$M\f$ will have \f$n_{target}\f$ rows and 37 : * \f$n_{source}\f$ columns so that \f$f_{target} = M f_{source}\f$ 38 : * Formally, this computes the sum 39 : * \f[ n w_j = 1 + 2 \sum_{k=1}^{\lfloor (n-1)/2 \rfloor} \cos(k(x - X_j)) 40 : * \left[ + \cos\left(\frac{n}{2}(x - X_j)\right) \right] \f] 41 : * for each target point \f$x\f$, where \f$ X_j = \frac{2 \pi j}{n}\f$, and 42 : * the term in brackets is evaluated only if \f$n\f$ is even. 43 : * 44 : */ 45 : template <typename TargetDataType> 46 1 : Matrix fourier_interpolation_matrix(const TargetDataType& x_target, 47 : size_t n_source_points); 48 : } // namespace intrp