[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] odd/brent a36f54b 2/8: Search for the square root of
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] odd/brent a36f54b 2/8: Search for the square root of two |
Date: |
Fri, 18 Jun 2021 20:19:10 -0400 (EDT) |
branch: odd/brent
commit a36f54ba8174eb839d766aa077b0fd1ea0659d21
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Search for the square root of two
Compare iterations against this published example:
https://www.embeddedrelated.com/showarticle/855.php
| Let’s give it a spin to find \( \sqrt{2} \):
The trace for Chandrupatla's method matches closely, differing slightly
only for the last two iterations, e.g.:
| i= 9, x=1.414214, y=2.000000, err=-2.88658e-15
compared to an error term of -2.22045e-15 in the lmi unit test. This
example is therefore a witness supporting the hypothesis that the C++
and python implementations are substantially the same.
The 'brent' and 'genuine brent' traces are perfectly identical, and
match the "embeddedrelated" values. Both require eight (postinitial)
function evaluations, whereas 'chand' requires nine, so this example
does not support a hypothesis that 'chand' is better.
---
zero_test.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/zero_test.cpp b/zero_test.cpp
index 4b2d3c6..de22b9e 100644
--- a/zero_test.cpp
+++ b/zero_test.cpp
@@ -113,11 +113,11 @@ struct e_functor
struct e_nineteenth
{
- double operator()(double z) {return std::pow(z, 19);} // -1.0 , 4.0
+// double operator()(double z) {return std::pow(z, 19);} // -1.0 , 4.0
// double operator()(double z) {return std::cos(z) - 0.999;} // -0.01, 0.8
// double operator()(double z) {return std::pow(z - 1.7, 17.0);} // 0.0 , 2.0
// double operator()(double z) {return std::pow((z - 1.0), 3);} // 0.0 , 1.8
-// double operator()(double z) {return std::pow(z, 2.0) - 2.0;} // 0.0 , 2.0
+ double operator()(double z) {return std::pow(z, 2.0) - 2.0;} // 0.0 , 2.0
};
/// A function that's unfriendly to the secant method.
@@ -275,8 +275,8 @@ int test_main(int, char*[])
// 195 Brent's table 4.1 (IBM 360)
// 171 x86_64 brent_zero (IEEE 754)
// 169 x86_64 decimal_root (differs slightly due to rounding)
- double lo = -1.00;
- double hi = 4.0 ;
+ double lo = 0.0 ;
+ double hi = 2.0 ;
std::cout << "test genuine brent" << std::endl;
double d = brent_zero(lo, hi, 1.0e-16, e_19);
// LMI_TEST(std::fabs(d) <= epsilon);
- [lmi-commits] [lmi] odd/brent updated (8ccfa28 -> e2b9e33), Greg Chicares, 2021/06/18
- [lmi-commits] [lmi] odd/brent a36f54b 2/8: Search for the square root of two,
Greg Chicares <=
- [lmi-commits] [lmi] odd/brent 3bd7713 4/8: Try again / Flail again / Flail better, Greg Chicares, 2021/06/18
- [lmi-commits] [lmi] odd/brent ec32d2b 5/8: Transplant Chandrupatla's condition into some Brent code, Greg Chicares, 2021/06/18
- [lmi-commits] [lmi] odd/brent ea32ee0 1/8: Suppress unwanted output, Greg Chicares, 2021/06/18
- [lmi-commits] [lmi] odd/brent a24eea7 3/8: Find a root of cos(x)-0.999, Greg Chicares, 2021/06/18
- [lmi-commits] [lmi] odd/brent 0ad36f9 6/8: Display Brent and Chandrupatla conditions, Greg Chicares, 2021/06/18
- [lmi-commits] [lmi] odd/brent b60b29b 7/8: Test Chandrupatla condition in genuine brent code, Greg Chicares, 2021/06/18
- [lmi-commits] [lmi] odd/brent e2b9e33 8/8: Let Chandrupatla reject IQI when Brent would accept it, Greg Chicares, 2021/06/18