2 Copyright 2017 Nick Thompson
4 Distributed under the Boost Software License, Version 1.0.
5 (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt).
9 [section:barycentric Barycentric Rational Interpolation]
14 #include <boost/math/interpolators/barycentric_rational.hpp>
16 namespace boost{ namespace math{
18 class barycentric_rational
21 template <class InputIterator1, class InputIterator2>
22 barycentric_rational(InputIterator1 start_x, InputIterator1 end_x, InputIterator2 start_y, size_t approximation_order = 3);
24 barycentric_rational(std::vector<Real>&& x, std::vector<Real>&& y, size_t order = 3);
26 barycentric_rational(const Real* const x, const Real* const y, size_t n, size_t approximation_order = 3);
28 Real operator()(Real x) const;
30 Real prime(Real x) const;
32 std::vector<Real>&& return_x();
34 std::vector<Real>&& return_y();
43 Barycentric rational interpolation is a high-accuracy interpolation method for non-uniformly spaced samples.
44 It requires [bigo](/N/) time for construction, and [bigo](/N/) time for each evaluation.
45 Linear time evaluation is not optimal; for instance the cubic B-spline can be evaluated in constant time.
46 However, using the cubic B-spline requires uniformly-spaced samples, which are not always available.
48 Use of the class requires a vector of independent variables `x[0]`, `x[1]`, .... `x[n-1]` where `x[i+1] > x[i]`,
49 and a vector of dependent variables `y[0]`, `y[1]`, ... , `y[n-1]`.
52 std::vector<double> x(500);
53 std::vector<double> y(500);
54 // populate x, y, then:
55 boost::math::barycentric_rational<double> interpolant(std::move(x), std::move(y));
57 This implicitly calls the constructor with approximation order 3, and hence the accuracy is [bigo](/h/[super 4]).
58 In general, if you require an approximation order /d/, then the error is [bigo](/h/[super /d/+1]).
59 A call to the constructor with an explicit approximation order is demonstrated below
61 boost::math::barycentric_rational<double> interpolant(std::move(x), std::move(y), 5);
63 To evaluate the interpolant, simply use
66 double y = interpolant(x);
68 and to evaluate its derivative use
70 double y = interpolant.prime(x);
72 If you no longer require the interpolant, then you can get your data back:
74 std::vector<double> xs = interpolant.return_x();
75 std::vector<double> ys = interpolant.return_y();
77 Be aware that once you return your data, the interpolant is *dead*.
81 Although this algorithm is robust, it can surprise you.
82 The main way this occurs is if the sample spacing at the endpoints is much larger than the spacing in the center.
83 This is to be expected; all interpolants perform better in the opposite regime,
84 where samples are clustered at the endpoints and somewhat uniformly spaced throughout the center.
86 A desirable property of any interpolator /f/ is that for all
87 /x/[sub min] [le] /x/ [le] /x/[sub max], also /y/[sub min] [le] /f/(/x/) [le] /y/[sub max].
89 /This property does not hold for the barycentric rational interpolator./
90 However, unless you deliberately try to antagonize this interpolator (by, for instance, placing the final value far from all the rest),
91 you will probably not fall victim to this problem.
93 The reference used for implementation of this algorithm is
94 [@https://web.archive.org/save/_embed/http://www.mn.uio.no/math/english/people/aca/michaelf/papers/rational.pdf Barycentric rational interpolation with no poles and a high rate of interpolation], and the evaluation of the derivative is given by [@http://www.ams.org/journals/mcom/1986-47-175/S0025-5718-1986-0842136-8/S0025-5718-1986-0842136-8.pdf Some New Aspects of Rational Interpolation].
98 [import ../../example/barycentric_interpolation_example.cpp]
99 [import ../../example/barycentric_interpolation_example_2.cpp]
101 [barycentric_rational_example]
103 [barycentric_rational_example2]
105 [barycentric_rational_example2_out]
107 [endsect] [/section:barycentric Barycentric Rational Interpolation]