Tudat/Mathematics/NumericalQuadrature/UnitTests/unitTestTrapezoidQuadrature.cpp
//! Test if qudrature is computed correctly (exponential function).
Test if qudrature is computed correctly (exponential function).
Test if qudrature is computed correctly ( exponential function ) .
BOOST_AUTO_TEST_CASE( testIntegralExpFunction )
{
    int numberOfSamples = 1E4;
    std::vector< double > bounds( 2 );
    bounds[ 0 ] = 0.0;
    bounds[ 1 ] = 2.0;
    std::vector< double > independentVariables = linspace( bounds[ 0 ], bounds[ 1 ], numberOfSamples );
    std::vector< double > dependentVariables( 0 );
    for( unsigned int i = 0 ; i < independentVariables.size() ; i++ )
    {
        dependentVariables.push_back( std::exp( independentVariables[ i ] ) );
    }
    tudat::numerical_quadrature::TrapezoidNumericalQuadrature< double, double > integrator(
                independentVariables, dependentVariables );
    double expectedIntegral = std::exp( 2.0 ) - std::exp( 0.0 );
    double computedIntegralTrapezoid = integrator.getQuadrature( );
    double computedIntegralSimpson = tudat::numerical_quadrature::performExtendedSimpsonsQuadrature(
                independentVariables.at( 1 ) - independentVariables.at( 0 ), dependentVariables );
    BOOST_CHECK_CLOSE_FRACTION( computedIntegralTrapezoid, expectedIntegral, 1E-8 );
    BOOST_CHECK_CLOSE_FRACTION( computedIntegralSimpson, expectedIntegral, 1E-8 );
}
BOOST_AUTO_TEST_CASE ( testIntegralExpFunction ) { int numberOfSamples = 1E4 ; std :: vector < double > bounds ( 2 ) ; bounds [ 0 ] = 0.0 ; bounds [ 1 ] = 2.0 ; std :: vector < double > independentVariables = linspace ( bounds [ 0 ] , bounds [ 1 ] , numberOfSamples ) ; std :: vector < double > dependentVariables ( 0 ) ; for ( unsigned int i = 0 ; i < independentVariables . size ( ) ; i ++ ) { dependentVariables . push_back ( std :: exp ( independentVariables [ i ] ) ) ; } tudat :: numerical_quadrature :: TrapezoidNumericalQuadrature < double , double > integrator ( independentVariables , dependentVariables ) ; double expectedIntegral = std :: exp ( 2.0 ) - std :: exp ( 0.0 ) ; double computedIntegralTrapezoid = integrator . getQuadrature ( ) ; double computedIntegralSimpson = tudat :: numerical_quadrature :: performExtendedSimpsonsQuadrature ( independentVariables . at ( 1 ) - independentVariables . at ( 0 ) , dependentVariables ) ; BOOST_CHECK_CLOSE_FRACTION ( computedIntegralTrapezoid , expectedIntegral , 1E-8 ) ; BOOST_CHECK_CLOSE_FRACTION ( computedIntegralSimpson , expectedIntegral , 1E-8 ) ; }
Test if qudrature is computed correctly (exponential function).
Test if qudrature is computed correctly ( exponential function ) .
// Generate independent variables // Create integrator // Check if computed sample mean matches expected value.