[/
  Copyright 2017 Nick Thompson

  Distributed under the Boost Software License, Version 1.0.
  (See accompanying file LICENSE_1_0.txt or copy at
  http://www.boost.org/LICENSE_1_0.txt).
]

[section:barycentric Barycentric Rational Interpolation]

[heading Synopsis]

``
#include <boost/math/tools/barycentric_rational_interpolation.hpp>

namespace boost{ namespace math{
    template<class Real>
    class barycentric_rational
    {
    public:
	    template <class InputIterator1, class InputIterator2>
        barycentric_rational(InputIterator1 start_x, InputIterator1 end_x, InputIterator2 start_y, size_t approximation_order = 3);
        barycentric_rational(const Real* const x, const Real* const y, size_t n, size_t approximation_order = 3);

        Real operator()(Real x) const;
    };

}}
``


[heading Description]

Barycentric rational interpolation is a high-accuracy interpolation method for non-uniformly spaced samples.
It requires [bigo](N) time for construction, and [bigo](N) time for each evaluation.
Linear time evaluation is not optimal; for instance the cubic B-spline can be evaluated in constant time.
However, using the cubic b spline requires uniformly spaced samples, which are not always available.

Use of the class requires a vector of independent variables x[0], x[1], .... x[n-1] where x[i+1] > x[i],
and a vector of dependent variables y[0], y[1], ... , y[n-1].
The call is trivial:

    boost::math::tools::barycentric_rational<double> interpolant(x.data(), y.data(), y.size());

This implicitly calls the constructor with approximation order 3, and hence the accuracy is [bigo](h[super 4]).
In general, if you require an approximation order /d/, then the error is [bigo](h[super d+1]).
A call to the constructor with an explicit approximation order could be

    boost::math::tools::barycentric_rational<double> interpolant(x.data(), y.data(), y.size(), 5);

To evaluate the interpolant, simply use

    double x = 2.3;
    double y = interpolant(x);

Although this algorithm is robust, it can surprise you.
The main way this occurs is if the sample spacing at the endpoints is much larger than the spacing in the center.
This is to be expected; all interpolants perform better in the opposite regime, where samples are clustered at the endpoints and somewhat uniformly spaced throughout the center.


The reference used for implementation of this algorithm is [@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].

[heading Examples]

[import ../../example/barycentric_interpolation_example.cpp]
[import ../../example/barycentric_interpolation_example_2.cpp]

[barycentric_rational_example]

[barycentric_rational_example2]

[barycentric_rational_example2_out]


[endsect] [/section:barycentric Barycentric Rational Interpolation]
