2 * Copyright Nick Thompson, 2019
3 * Use, modification and distribution are subject to the
4 * Boost Software License, Version 1.0. (See accompanying file
5 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #include "math_unit_test.hpp"
11 #include <boost/math/interpolators/cardinal_quadratic_b_spline.hpp>
12 using boost::math::interpolators::cardinal_quadratic_b_spline
;
19 Real h
= Real(1)/Real(16);
21 std::vector
<Real
> v(n
, c
);
22 auto qbs
= cardinal_quadratic_b_spline
<Real
>(v
.data(), v
.size(), t0
, h
);
27 CHECK_ULP_CLOSE(c
, qbs(t
), 2);
28 CHECK_MOLLIFIED_CLOSE(0, qbs
.prime(t
), 100*std::numeric_limits
<Real
>::epsilon());
34 Real t
= t0
+ i
*h
+ h
/2;
35 CHECK_ULP_CLOSE(c
, qbs(t
), 2);
36 CHECK_MOLLIFIED_CLOSE(0, qbs
.prime(t
), 300*std::numeric_limits
<Real
>::epsilon());
38 CHECK_ULP_CLOSE(c
, qbs(t
), 2);
39 CHECK_MOLLIFIED_CLOSE(0, qbs
.prime(t
), 150*std::numeric_limits
<Real
>::epsilon());
50 Real h
= Real(1)/Real(16);
52 std::vector
<Real
> y(n
);
53 for (size_t i
= 0; i
< n
; ++i
) {
57 auto qbs
= cardinal_quadratic_b_spline
<Real
>(y
.data(), y
.size(), t0
, h
);
62 CHECK_ULP_CLOSE(m
*t
+b
, qbs(t
), 2);
63 CHECK_ULP_CLOSE(m
, qbs
.prime(t
), 820);
69 Real t
= t0
+ i
*h
+ h
/2;
70 CHECK_ULP_CLOSE(m
*t
+b
, qbs(t
), 2);
71 CHECK_MOLLIFIED_CLOSE(m
, qbs
.prime(t
), 1500*std::numeric_limits
<Real
>::epsilon());
73 CHECK_ULP_CLOSE(m
*t
+b
, qbs(t
), 3);
74 CHECK_MOLLIFIED_CLOSE(m
, qbs
.prime(t
), 1500*std::numeric_limits
<Real
>::epsilon());
86 Real h
= Real(1)/Real(16);
88 std::vector
<Real
> y(n
);
89 for (size_t i
= 0; i
< n
; ++i
) {
91 y
[i
] = a
*t
*t
+ b
*t
+ c
;
93 Real t_max
= t0
+ (n
-1)*h
;
94 auto qbs
= cardinal_quadratic_b_spline
<Real
>(y
, t0
, h
, b
, 2*a
*t_max
+ b
);
99 CHECK_ULP_CLOSE(a
*t
*t
+ b
*t
+ c
, qbs(t
), 2);
105 Real t
= t0
+ i
*h
+ h
/2;
106 CHECK_ULP_CLOSE(a
*t
*t
+ b
*t
+ c
, qbs(t
), 47);
109 if (!CHECK_ULP_CLOSE(a
*t
*t
+ b
*t
+ c
, qbs(t
), 104)) {
110 std::cerr
<< " Problem abscissa t = " << t
<< "\n";
118 test_constant
<float>();
119 test_constant
<double>();
120 test_constant
<long double>();
122 test_linear
<float>();
123 test_linear
<double>();
124 test_linear
<long double>();
126 test_quadratic
<double>();
127 test_quadratic
<long double>();
129 return boost::math::test::report_errors();