20#ifndef quantlib_lagrange_interpolation_hpp
21#define quantlib_lagrange_interpolation_hpp
25#if defined(QL_EXTRA_SAFETY_CHECKS)
43 template <
class I1,
class I2>
52 n_(
std::distance(xBegin, xEnd)),
54 #if defined(QL_EXTRA_SAFETY_CHECKS)
56 "x values must not contain duplicates");
63 for (
Size i=0; i <
n_; ++i) {
67 for (
Size j=0; j <
n_; ++j) {
78 Real n=0.0,
d=0.0, nd=0.0, dd=0.0;
79 for (
Size i=0; i <
n_; ++i) {
84 for (
Size j=0; j <
n_; ++j)
96 nd += alphad * this->yBegin_[i];
99 return (nd *
d -
n * dd)/(
d*
d);
103 QL_FAIL(
"LagrangeInterpolation primitive is not implemented");
107 QL_FAIL(
"LagrangeInterpolation secondDerivative "
108 "is not implemented");
114 template <
class Iterator>
118 const auto iter = std::lower_bound(
120 if (iter != this->
xEnd_ && *iter - x < eps) {
121 return yBegin[std::distance(this->
xBegin_, iter)];
125 for (
Size i = 0; i <
n_; ++i) {
144 template <
class I1,
class I2>
147 impl_ = ext::make_shared<detail::LagrangeInterpolationImpl<I1,I2> >(
148 xBegin, xEnd, yBegin);
154 return ext::dynamic_pointer_cast<detail::UpdatedYInterpolation>
1-D array used in linear algebra.
1-D array used in linear algebra.
basic template implementation
templateImpl(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, const int requiredPoints=2)
base class for 1-D interpolations.
ext::shared_ptr< Impl > impl_
Real value(const Array &y, Real x) const
LagrangeInterpolation(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin)
Real _value(const Iterator &yBegin, Real x) const
Real value(Real x) const override
Real secondDerivative(Real) const override
Real primitive(Real) const override
Real value(const Array &y, Real x) const override
Real derivative(Real x) const override
LagrangeInterpolationImpl(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin)
virtual ~UpdatedYInterpolation()=default
virtual Real value(const Array &yValues, Real x) const =0
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
std::size_t Size
size of a container
base class for 1-D interpolations
bool close_enough(const Quantity &m1, const Quantity &m2, Size n)