Tudat/Mathematics/RootFinders/UnitTests/unitTestNewtonRaphson.cpp
//! Check if Newton-Raphson converges on test function #1 (TestFunction1).
Check if Newton-Raphson converges on test function #1 (TestFunction1).
Check if Newton - Raphson converges on test function #1 ( TestFunction1 ) .
BOOST_AUTO_TEST_CASE( test_newtonRaphson_testFunction1 )
{
    std::shared_ptr< TestFunction1 > testFunction = std::make_shared< TestFunction1 >( 1 );
    NewtonRaphson::TerminationFunction terminationConditionFunction =
            std::bind( &RootAbsoluteToleranceTerminationCondition< double >::checkTerminationCondition,
                         std::make_shared< RootAbsoluteToleranceTerminationCondition< double > >(
                             testFunction->getTrueRootAccuracy( ) ), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
    NewtonRaphson newtonRaphson( terminationConditionFunction );
    const double root = newtonRaphson.execute( testFunction, testFunction->getInitialGuess( ) );
    BOOST_CHECK_CLOSE_FRACTION( root, testFunction->getTrueRootLocation( ), 1.0e-15 );
    BOOST_CHECK_LT( testFunction->evaluate( root ), testFunction->getTrueRootAccuracy( ) );
}
BOOST_AUTO_TEST_CASE ( test_newtonRaphson_testFunction1 ) { std :: shared_ptr < TestFunction1 > testFunction = std :: make_shared < TestFunction1 > ( 1 ) ; NewtonRaphson :: TerminationFunction terminationConditionFunction = std :: bind ( & RootAbsoluteToleranceTerminationCondition < double > :: checkTerminationCondition , std :: make_shared < RootAbsoluteToleranceTerminationCondition < double > > ( testFunction -> getTrueRootAccuracy ( ) ) , std :: placeholders :: _1 , std :: placeholders :: _2 , std :: placeholders :: _3 , std :: placeholders :: _4 , std :: placeholders :: _5 ) ; NewtonRaphson newtonRaphson ( terminationConditionFunction ) ; const double root = newtonRaphson . execute ( testFunction , testFunction -> getInitialGuess ( ) ) ; BOOST_CHECK_CLOSE_FRACTION ( root , testFunction -> getTrueRootLocation ( ) , 1.0e-15 ) ; BOOST_CHECK_LT ( testFunction -> evaluate ( root ) , testFunction -> getTrueRootAccuracy ( ) ) ; }
Check if Newton-Raphson converges on test function #1 (TestFunction1).
Check if Newton - Raphson converges on test function #1 ( TestFunction1 ) .
// Create object containing the test functions. // The termination condition. // Test Newton-Raphson object. // Let Newton-Raphson search for the root. // Check if the result is within the requested accuracy.