• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Nick Thompson, 2019
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6 
7 #ifndef BOOST_MATH_INTERPOLATORS_CARDINAL_QUADRATIC_B_SPLINE_HPP
8 #define BOOST_MATH_INTERPOLATORS_CARDINAL_QUADRATIC_B_SPLINE_HPP
9 #include <memory>
10 #include <boost/math/interpolators/detail/cardinal_quadratic_b_spline_detail.hpp>
11 
12 
13 namespace boost{ namespace math{ namespace interpolators {
14 
15 template <class Real>
16 class cardinal_quadratic_b_spline
17 {
18 public:
19     // If you don't know the value of the derivative at the endpoints, leave them as nans and the routine will estimate them.
20     // y[0] = y(a), y[n - 1] = y(b), step_size = (b - a)/(n -1).
cardinal_quadratic_b_spline(const Real * const y,size_t n,Real t0,Real h,Real left_endpoint_derivative=std::numeric_limits<Real>::quiet_NaN (),Real right_endpoint_derivative=std::numeric_limits<Real>::quiet_NaN ())21     cardinal_quadratic_b_spline(const Real* const y,
22                                 size_t n,
23                                 Real t0 /* initial time, left endpoint */,
24                                 Real h  /*spacing, stepsize*/,
25                                 Real left_endpoint_derivative = std::numeric_limits<Real>::quiet_NaN(),
26                                 Real right_endpoint_derivative = std::numeric_limits<Real>::quiet_NaN())
27      : impl_(std::make_shared<detail::cardinal_quadratic_b_spline_detail<Real>>(y, n, t0, h, left_endpoint_derivative, right_endpoint_derivative))
28     {}
29 
30     // Oh the bizarre error messages if we template this on a RandomAccessContainer:
cardinal_quadratic_b_spline(std::vector<Real> const & y,Real t0,Real h,Real left_endpoint_derivative=std::numeric_limits<Real>::quiet_NaN (),Real right_endpoint_derivative=std::numeric_limits<Real>::quiet_NaN ())31     cardinal_quadratic_b_spline(std::vector<Real> const & y,
32                                 Real t0 /* initial time, left endpoint */,
33                                 Real h  /*spacing, stepsize*/,
34                                 Real left_endpoint_derivative = std::numeric_limits<Real>::quiet_NaN(),
35                                 Real right_endpoint_derivative = std::numeric_limits<Real>::quiet_NaN())
36      : impl_(std::make_shared<detail::cardinal_quadratic_b_spline_detail<Real>>(y.data(), y.size(), t0, h, left_endpoint_derivative, right_endpoint_derivative))
37     {}
38 
39 
operator ()(Real t) const40     Real operator()(Real t) const {
41         return impl_->operator()(t);
42     }
43 
prime(Real t) const44     Real prime(Real t) const {
45        return impl_->prime(t);
46     }
47 
t_max() const48     Real t_max() const {
49         return impl_->t_max();
50     }
51 
52 private:
53     std::shared_ptr<detail::cardinal_quadratic_b_spline_detail<Real>> impl_;
54 };
55 
56 }}}
57 #endif
58