34 #include "DGtal/base/Common.h"
35 #include "DGtal/math/LagrangeInterpolation.h"
36 #include "DGtal/math/MPolynomial.h"
37 #include "DGtalCatch.h"
41 using namespace DGtal;
48 SCENARIO(
"LagrangeInterpolation< int64_t > unit tests",
"[lagrange_interpolation]" )
52 typedef LInterp::Polynomial Polynomial;
54 GIVEN(
"A polynomial of degree 2 and 3 interpolation points" ) {
55 Polynomial P1 = mmonomial<Ring>( 2 );
56 std::vector< Ring > X = { 1, 2, 3 };
57 std::vector< Ring > Y;
58 for (
auto x : X ) Y.push_back( P1( x ) );
61 THEN(
"Its Lagrange polynomial is itself" ) {
62 auto Lag1 = L1.polynomial( Y );
63 REQUIRE( Lag1 == P1 * L1.denominator() );
67 GIVEN(
"A polynomial of degree 3 and 4 interpolation points" ) {
68 Polynomial P2 = mmonomial<Ring>( 3 ) + 3*mmonomial<Ring>( 1 ) ;
69 std::vector< Ring > X = { -1, 1, 2, 3 };
70 std::vector< Ring > Y;
71 for (
auto x : X ) Y.push_back( P2( x ) );
74 THEN(
"Its Lagrange polynomial is itself" ) {
75 auto Lag2 = L2.polynomial( Y );
76 REQUIRE( Lag2 == P2 * L2.denominator() );
80 GIVEN(
"3 interpolation points (0,1), (1,3), (2,6)" ) {
81 std::vector< Ring > X = { 0, 1, 2 };
82 std::vector< Ring > Y = { 1, 3, 6 };
85 THEN(
"Its Lagrange polynomial is 1/2*(2+3x+x^2)" ) {
86 auto Lag3 = L3.polynomial( Y );
87 Polynomial Exp3 = mmonomial<Ring>( 2 ) + 3 * mmonomial<Ring>( 1 ) + 2;
92 GIVEN(
"3 interpolation points (0,1), (1,7), (2,20)" ) {
93 std::vector< Ring > X = { 0, 1, 2 };
94 std::vector< Ring > Y = { 1, 7, 20 };
97 THEN(
"Its Lagrange polynomial is 1/2*(2+5x+7x^2)" ) {
98 auto Lag4 = L4.polynomial( Y );
99 Polynomial Exp4 = 7 * mmonomial<Ring>( 2 ) + 5 * mmonomial<Ring>( 1 ) + 2;
Aim: This class implements Lagrange basis functions and Lagrange interpolation.
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
GIVEN("A cubical complex with random 3-cells")
SCENARIO("LagrangeInterpolation< int64_t > unit tests", "[lagrange_interpolation]")
REQUIRE(domain.isInside(aPoint))