Tudat/Mathematics/RootFinders/UnitTests/unitTestNewtonRaphson.cpp
//! Check if Newton-Raphson converges on function with zero root (testFunctionWithZeroRoot).
// Not the best test case. Inheritance from old code. Not really relevant anymore. The basic
// idea is that Newton-Raphson should work for both a function that becomes zero, as well as for a
// function that does not become zero. A better case should be written.
Check if Newton-Raphson converges on function with zero root (testFunctionWithZeroRoot).
Not the best test case. Inheritance from old code. Not really relevant anymore. The basic
idea is that Newton-Raphson should work for both a function that becomes zero, as well as for a
function that does not become zero. A better case should be written.
Check if Newton - Raphson converges on function with zero root ( testFunctionWithZeroRoot ) . Not the best test case . Inheritance from old code . Not really relevant anymore . The basic idea is that Newton - Raphson should work for both a function that becomes zero as well as for a function that does not become zero . A better case should be written .
BOOST_AUTO_TEST_CASE( test_newtonRaphson_testFunctionWithZeroRoot )
{
    std::shared_ptr< TestFunctionWithZeroRoot > testFunction =
            std::make_shared< TestFunctionWithZeroRoot >( 1 );
    NewtonRaphson::TerminationFunction terminationConditionFunction
            = std::bind(
                &RootAbsoluteOrRelativeToleranceTerminationCondition< >::
                checkTerminationCondition,
                std::make_shared< RootAbsoluteOrRelativeToleranceTerminationCondition< > >(
                    1.0e-308, 1.0e-15 ), 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_SMALL( root, 1.0e-150 );
    BOOST_CHECK_LT( testFunction->evaluate( root ), testFunction->getTrueRootAccuracy( ) );
}
BOOST_AUTO_TEST_CASE ( test_newtonRaphson_testFunctionWithZeroRoot ) { std :: shared_ptr < TestFunctionWithZeroRoot > testFunction = std :: make_shared < TestFunctionWithZeroRoot > ( 1 ) ; NewtonRaphson :: TerminationFunction terminationConditionFunction = std :: bind ( & RootAbsoluteOrRelativeToleranceTerminationCondition < > :: checkTerminationCondition , std :: make_shared < RootAbsoluteOrRelativeToleranceTerminationCondition < > > ( 1.0e-308 , 1.0e-15 ) , 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_SMALL ( root , 1.0e-150 ) ; BOOST_CHECK_LT ( testFunction -> evaluate ( root ) , testFunction -> getTrueRootAccuracy ( ) ) ; }
Check if Newton-Raphson converges on function with zero root (testFunctionWithZeroRoot).
Check if Newton - Raphson converges on function with zero root ( testFunctionWithZeroRoot ) .
// 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.