Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:41:22

0001 // Copyright Nick Thompson, 2017
0002 // Use, modification and distribution are subject to the
0003 // Boost Software License, Version 1.0.
0004 // (See accompanying file LICENSE_1_0.txt
0005 // or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // This implements the compactly supported cubic b spline algorithm described in
0008 // Kress, Rainer. "Numerical analysis, volume 181 of Graduate Texts in Mathematics." (1998).
0009 // Splines of compact support are faster to evaluate and are better conditioned than classical cubic splines.
0010 
0011 // Let f be the function we are trying to interpolate, and s be the interpolating spline.
0012 // The routine constructs the interpolant in O(N) time, and evaluating s at a point takes constant time.
0013 // The order of accuracy depends on the regularity of the f, however, assuming f is
0014 // four-times continuously differentiable, the error is of O(h^4).
0015 // In addition, we can differentiate the spline and obtain a good interpolant for f'.
0016 // The main restriction of this method is that the samples of f must be evenly spaced.
0017 // Look for barycentric rational interpolation for non-evenly sampled data.
0018 // Properties:
0019 // - s(x_j) = f(x_j)
0020 // - All cubic polynomials interpolated exactly
0021 
0022 #ifndef BOOST_MATH_INTERPOLATORS_CARDINAL_CUBIC_B_SPLINE_HPP
0023 #define BOOST_MATH_INTERPOLATORS_CARDINAL_CUBIC_B_SPLINE_HPP
0024 
0025 #include <boost/math/interpolators/detail/cardinal_cubic_b_spline_detail.hpp>
0026 
0027 namespace boost{ namespace math{ namespace interpolators {
0028 
0029 template <class Real>
0030 class cardinal_cubic_b_spline
0031 {
0032 public:
0033     // If you don't know the value of the derivative at the endpoints, leave them as nans and the routine will estimate them.
0034     // f[0] = f(a), f[length -1] = b, step_size = (b - a)/(length -1).
0035     template <class BidiIterator>
0036     cardinal_cubic_b_spline(const BidiIterator f, BidiIterator end_p, Real left_endpoint, Real step_size,
0037                    Real left_endpoint_derivative = std::numeric_limits<Real>::quiet_NaN(),
0038                    Real right_endpoint_derivative = std::numeric_limits<Real>::quiet_NaN());
0039     cardinal_cubic_b_spline(const Real* const f, size_t length, Real left_endpoint, Real step_size,
0040        Real left_endpoint_derivative = std::numeric_limits<Real>::quiet_NaN(),
0041        Real right_endpoint_derivative = std::numeric_limits<Real>::quiet_NaN());
0042 
0043     cardinal_cubic_b_spline() = default;
0044     Real operator()(Real x) const;
0045 
0046     Real prime(Real x) const;
0047 
0048     Real double_prime(Real x) const;
0049 
0050 private:
0051     std::shared_ptr<detail::cardinal_cubic_b_spline_imp<Real>> m_imp;
0052 };
0053 
0054 template<class Real>
0055 cardinal_cubic_b_spline<Real>::cardinal_cubic_b_spline(const Real* const f, size_t length, Real left_endpoint, Real step_size,
0056                                      Real left_endpoint_derivative, Real right_endpoint_derivative) : m_imp(std::make_shared<detail::cardinal_cubic_b_spline_imp<Real>>(f, f + length, left_endpoint, step_size, left_endpoint_derivative, right_endpoint_derivative))
0057 {
0058 }
0059 
0060 template <class Real>
0061 template <class BidiIterator>
0062 cardinal_cubic_b_spline<Real>::cardinal_cubic_b_spline(BidiIterator f, BidiIterator end_p, Real left_endpoint, Real step_size,
0063    Real left_endpoint_derivative, Real right_endpoint_derivative) : m_imp(std::make_shared<detail::cardinal_cubic_b_spline_imp<Real>>(f, end_p, left_endpoint, step_size, left_endpoint_derivative, right_endpoint_derivative))
0064 {
0065 }
0066 
0067 template<class Real>
0068 Real cardinal_cubic_b_spline<Real>::operator()(Real x) const
0069 {
0070     return m_imp->operator()(x);
0071 }
0072 
0073 template<class Real>
0074 Real cardinal_cubic_b_spline<Real>::prime(Real x) const
0075 {
0076     return m_imp->prime(x);
0077 }
0078 
0079 template<class Real>
0080 Real cardinal_cubic_b_spline<Real>::double_prime(Real x) const
0081 {
0082     return m_imp->double_prime(x);
0083 }
0084 
0085 
0086 }}}
0087 #endif