lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 0113a5d 3/8: Test three examples from a textb


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 0113a5d 3/8: Test three examples from a textbook
Date: Fri, 30 Jul 2021 16:14:47 -0400 (EDT)

branch: master
commit 0113a5d2d5dc36555167055e4efb762e28e4ffc5
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Test three examples from a textbook
    
    The textbook recommends Chandrupatla's method over Brent's; that
    recommendation will be evaluated here soon.
---
 zero_test.cpp | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/zero_test.cpp b/zero_test.cpp
index 1926b23..896268d 100644
--- a/zero_test.cpp
+++ b/zero_test.cpp
@@ -881,17 +881,34 @@ void test_various_functions()
     test_a_decimal_function(f03, root_03, -0.01, 0.8, 15     , __LINE__, 16);
     test_a_function        (f03, root_03, -0.01, 0.8, 1.0e-15, __LINE__);
 
+    // The next three examples are from _Computational Physics_,
+    // Philipp O. J. Scherer, 2nd ed., ISBN 978-3-319-00400-6,
+    // page 96; number of iterations estimated from graphs.
+
+    // Scherer, Fig. 6.10, iteration counts for 2ϵ tolerance:
+    //   10 vs. 10 here (Brent)
+    //    7             (Chandrupatla)
     auto f04 = [](double x) {return std::pow(x, 2.0) - 2.0;};
     auto root_04 = std::sqrt(2.0);
     test_a_decimal_function(f04, root_04, 0.0 , 2.0, 17     , __LINE__, 10);
     test_a_function        (f04, root_04, 0.0 , 2.0, 1.0e-15, __LINE__);
 
+    // Scherer, Fig. 6.11, iteration counts for 2ϵ tolerance:
+    //   126 vs. 130 here (Brent)
+    //    59              (Chandrupatla)
     auto f05 = [](double x) {return std::pow((x - 1.0), 3);};
     auto root_05 = 1.0;
     test_a_decimal_function(f05, root_05, 0.0 , 1.8, 17     , __LINE__, 130);
     test_a_function        (f05, root_05, 0.0 , 1.8, 1.0e-15, __LINE__);
 
-    // f06 coming soon
+    // Scherer, Fig. 6.12, iteration counts for 1.0e-12 tolerance
+    // (roundoff error in the computed function precludes 2ϵ):
+    //   124 vs. 107 here (Brent)
+    //    31              (Chandrupatla)
+    auto f06 = [](double x) {return std::pow(x, 25.0);};
+    auto root_06 = 0.0;
+    test_a_decimal_function(f06, root_06, -1.0 , 2.0, 12     , __LINE__, 107);
+    test_a_function        (f06, root_06, -1.0 , 2.0, 5.0e-13, __LINE__);
 
     // Despite its apparent insipidity, this is actually a very
     // interesting test: after the first iterate has been calculated



reply via email to

[Prev in Thread] Current Thread [Next in Thread]