Tudat/Mathematics/RootFinders/UnitTests/unitTestNewtonRaphson.cpp
//! Check if Newton-Raphson converges on function with large root difference
//! (testFunctionWithLargeRootDifference).
// Not the best test case. Inheritance from old code.
Check if Newton-Raphson converges on function with large root difference
(testFunctionWithLargeRootDifference).
Not the best test case. Inheritance from old code.
Check if Newton - Raphson converges on function with large root difference ( testFunctionWithLargeRootDifference ) . Not the best test case . Inheritance from old code .
BOOST_AUTO_TEST_CASE( test_newtonRaphson_testFunctionWithLargeRootDifference )
{
    const double tolerance = 1.0e-10;
    const double expectedRootLowCase = 1.00000000793634;
    const double expectedRootHighCase = 7937.3386333591;
    std::shared_ptr< TestFunctionWithLargeRootDifference > testFunctionLowCase =
            std::make_shared< TestFunctionWithLargeRootDifference >
            ( 1, -3.24859999867635e18, -3248600.0, 1.5707963267949 );
    std::shared_ptr< TestFunctionWithLargeRootDifference > testFunctionHighCase =
            std::make_shared< TestFunctionWithLargeRootDifference >
            ( 1, -3248600.0, -3.24859999867635e18, 1.5707963267949 );
    NewtonRaphson::TerminationFunction terminationConditionFunction
            = std::bind( &RootRelativeToleranceTerminationCondition< >::checkTerminationCondition,
                           std::make_shared< RootRelativeToleranceTerminationCondition< > >(
                               1.0e-10 ), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
    NewtonRaphson newtonRaphson( terminationConditionFunction );
    double rootLowCase = newtonRaphson.execute( testFunctionLowCase, 1.0 + 1.0e-10 );
    double rootHighCase = newtonRaphson.execute( testFunctionHighCase, 1.0 + 1.0e-2 );
    BOOST_CHECK_CLOSE_FRACTION( rootLowCase, expectedRootLowCase, tolerance );
    BOOST_CHECK_CLOSE_FRACTION( rootHighCase, expectedRootHighCase, tolerance );
}
BOOST_AUTO_TEST_CASE ( test_newtonRaphson_testFunctionWithLargeRootDifference ) { const double tolerance = 1.0e-10 ; const double expectedRootLowCase = 1.00000000793634 ; const double expectedRootHighCase = 7937.3386333591 ; std :: shared_ptr < TestFunctionWithLargeRootDifference > testFunctionLowCase = std :: make_shared < TestFunctionWithLargeRootDifference > ( 1 , -3.24859999867635e18 , -3248600.0 , 1.5707963267949 ) ; std :: shared_ptr < TestFunctionWithLargeRootDifference > testFunctionHighCase = std :: make_shared < TestFunctionWithLargeRootDifference > ( 1 , -3248600.0 , -3.24859999867635e18 , 1.5707963267949 ) ; NewtonRaphson :: TerminationFunction terminationConditionFunction = std :: bind ( & RootRelativeToleranceTerminationCondition < > :: checkTerminationCondition , std :: make_shared < RootRelativeToleranceTerminationCondition < > > ( 1.0e-10 ) , std :: placeholders :: _1 , std :: placeholders :: _2 , std :: placeholders :: _3 , std :: placeholders :: _4 , std :: placeholders :: _5 ) ; NewtonRaphson newtonRaphson ( terminationConditionFunction ) ; double rootLowCase = newtonRaphson . execute ( testFunctionLowCase , 1.0 + 1.0e-10 ) ; double rootHighCase = newtonRaphson . execute ( testFunctionHighCase , 1.0 + 1.0e-2 ) ; BOOST_CHECK_CLOSE_FRACTION ( rootLowCase , expectedRootLowCase , tolerance ) ; BOOST_CHECK_CLOSE_FRACTION ( rootHighCase , expectedRootHighCase , tolerance ) ; }
Check if Newton-Raphson converges on function with large root difference
(testFunctionWithLargeRootDifference).
Check if Newton - Raphson converges on function with large root difference ( testFunctionWithLargeRootDifference ) .
// Declare tolerance. // Declare expected roots. // Create objects containing the test functions. Values were obtained during a limit case // gravity assist calculation (while evaluating Cassini-1 trajectory). // The termination condition. // Make the Newton-Raphson object. // Let Newton-Raphson search for the root for both cases. // Check if the result is within the requested accuracy.